:
Code:
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 =NewDialog (context, r.style.translucent_dialog); Mdialog.setcontentview (view); ImageView Iv_cancel = (ImageView) View.findviewbyid (r.id.iv_cancel); Iv_cancel.setonclicklistener (NewView.onclicklistener () {@Override Public void OnClick(View v) {Mdialog.dismiss (); } }); }}
the style of the transparent background:
<stylename="Translucent_dialog"Parent="@android: Style/theme.dialog"> <!--Set the background transparency of the custom layout --<Item name="Android:background"> @android: color/transparent</Item> <!--Set window background transparent, that is, go to border--<Item name="Android:windowbackground"> @android: color/transparent</Item> <!--Set whether the activity background is dimmed--<Item name="Android:backgrounddimenabled">false</Item> </style>
change backgrounddimenabled To remove gray background, effect
Tip:
//想要有这种透明效果的对话框时,不用使用AlertDialog.Builder创建dialog,否则效果会异常
Custom dialog two or three things