dialog自定義彈框樣式
阿新 • • 發佈:2019-01-01
序
自定義dialog,有簡單和單獨重寫的
效果圖
簡單
Java程式碼: Dialog dialog = new Dialog(this, R.style.DialogStyle); dialog.setContentView(R.layout.start_dialog); dialog.show(); Style: <?xml version="1.0" encoding="utf-8"?> <resources> <style name="DialogStyle" parent="@android:style/Theme.Dialog"> <item name="android:windowBackground"> @android:color/transparent </item> //中間框是透明的 <item name="android:backgroundDimEnabled">false</item>//四周有沒有半透明黑色背景,false:沒有,true:有 </style> </resources>
重寫dialog:
/** * Created by zst on 2000/0/00. */ public class MapServiceDialog extends Dialog implements View.OnClickListener{ private Context mContext; public MapServiceDialog(Context context) { super(context); this.mContext = context; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.dialog_map_service); //this.getWindow().setBackgroundDrawable(new PaintDrawable(Color.TRANSPARENT)); //設定dialog屬性 //setCancelable(true); setCanceledOnTouchOutside(false); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.iv_close://關閉本dialog dismiss(); break; } } }