十一月專案小結(實現自定義底部以及自適應軟鍵盤Dialog)
阿新 • • 發佈:2018-12-03
自定義Dialog
- 自定義CustomDialog繼承父類Dialog
//style:自定義Dialog樣式
public CustomDialog(Activity activity , int style) {
super(activity,style);
}
- 設定Dialog載入位置
protected void setViewLocation() { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int height = dm.heightPixels; Window window = this.getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.x = 0; lp.y = height; lp.width = ViewGroup.LayoutParams.MATCH_PARENT; lp.height = ViewGroup.LayoutParams.WRAP_CONTENT; // 設定顯示位置 onWindowAttributesChanged(lp); }
- 設定Dialog自適應軟鍵盤
//在onCreate呼叫該方法即可,可實現軟鍵盤彈出,Dialog自主上移,軟鍵盤收回,Dialog自主下移
setCanceledOnTouchOutside(true);