如果是声明一各类
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 参数。
本文详细介绍了如何使用PopupWindow创建自定义对话框,包括设置布局、显示位置及如何与软键盘交互等关键技术点。
1326

被折叠的 条评论
为什么被折叠?



