标签:
public class ViewActivity extends Activity implements View.OnClickListener {
Dialog mDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
initDialog(this);
}
@Override
public void onClick(View v) {
mDialog.show();
}
public void initDialog(Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.view_share, null);
mDialog = new Dialog(context, R.style.Translucent_Dialog);
mDialog.setContentView(view);
ImageView iv_cancel = (ImageView) view.findViewById(R.id.iv_cancel);
iv_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDialog.dismiss();
}
});
}
}
<style name="Translucent_Dialog" parent="@android:style/Theme.Dialog">
<!-- 设置自定义布局的背景透明 -->
<item name="android:background">@android:color/transparent</item>
<!-- 设置window背景透明,也就是去边框 -->
<item name="android:windowBackground">@android:color/transparent</item>
<!-- 设置Activity背景是否变灰 -->
<item name="android:backgroundDimEnabled">false</item>
</style>
//想要有这种透明效果的对话框时,不用使用AlertDialog.Builder创建dialog,否则效果会异常
标签:
原文地址:http://blog.csdn.net/pengkv/article/details/50579246