使用popwindow製作彈出框與獲得焦點彈出軟鍵盤
阿新 • • 發佈:2019-01-24
如果是宣告一各類
public class VideoFilterDialog extends PopupWindow那麼在構造方法中新增:
conentView = inflater.inflate(R.layout.video_popup_filter, null); this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
this.setContentView(conentView);注意:上面的佈局大小,直接使用了ViewGroup;因為這個是最上層的父佈局,Linearlayout,Framlayout,Relativelayout都是繼承於它。也可以直接針對自己的佈局使用Linearlayout,Framlayout,Relativelayout的 LayoutParams。
彈出展示:
showAtLocation(parent, Gravity.NO_GRAVITY, x, y);parent是彈出框口的根佈局。
獲取焦點彈出軟鍵盤,並且將popwindow往上頂起:
this.setBackgroundDrawable(new BitmapDrawable()); this.setOutsideTouchable(false); this.setFocusable(true); //mEditInput.requestFocus(); this.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED); this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); this.showAtLocation(CommentCons.mFatherView, Gravity.BOTTOM, 0, 0);
說白了popwindow實現自動彈出軟鍵盤就是提供了
PopupWindow.INPUT_METHOD_NEEDED方法,ACTIVITY中提供setSoftInputMode()方法,為何在fragment中提供INPUT_METHOD_NEEDED 引數。