Android 自定义AlertDialog的写法和弹出软键盘和覆盖状态栏
private void showMyDialog(int layoutId){
AlertDialog myDialog = new
AlertDialog.Builder(context).create();
myDialog.show();
Window window = myDialog.getWindow();
window.setContentView(layoutId);
window.setGravity(Gravity.CENTER);
window.setLayout(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
}
方法 2
private void showMyDialog(int layoutId){
LayoutInflater inflater = LayoutInflater.from(mContext);
View fourView = inflater.inflate(layoutId, null);
AlertDialog myDialog = new
AlertDialog.Builder(context).create();
myDialog.show();
myDialog.getWindow().setContentView(fourView);
}
以上二种方法都可以自定义Dialog,并且效果还不错,但是如果Dialog里面有EditText就会遇到一个问题,怎么样
都打不开软键盘,也就无法输入,如果碰到这种情况的话,请看第三种写法:
方法 3
private void showMyDialog(int layoutId){
LayoutInflater inflater = LayoutInflater.from(mContext);
View fourView = inflater.inflate(layoutId, null);
AlertDialog myDialog = new
AlertDialog.Builder(context).create();
//加上以下这句代码
myDialog.setView(((Activity)
mContext).getLayoutInflater().inflate(layoutId, null))
myDialog.show();
myDialog.getWindow().setContentView(fourView);
}
全屏覆盖状态栏显示加上以下代码:
window.setType(WindowManager.LayoutParams.TYPE_APPLICATION_PANEL);
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
弹出软键盘:
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(passwordEt, InputMethodManager.SHOW_FORCED);
隐藏软键盘:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(mPasswordInputEt.getWindowToken(),);
Android 自定义AlertDialog的写法和弹出软键盘和覆盖状态栏的更多相关文章
- Android开发禁止首次进入activity弹出软键盘,限制屏幕只能竖屏或者横屏展示
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 只需在在Manifest.xml中设定activity的属性为: android:windowSoft ...
- Android为TV端助力之弹出软键盘方式
- Android 显示Dialog的同时自动弹出软键盘;
需求大致就是这样的:用户点击按钮弹出Dialog,Dialog中有输入框,然后Dialog弹出后要自动弹出软键盘:(如果让用户自己手动点击输入框再弹出软键盘的话,用户体验太差了): 好的,需求大致就是 ...
- (原)android的alertdialog中加入edittext但是不弹出软键盘等问题的解决与原因
摘要:alertdialog中加入edittext但是不弹出软键盘等问题网上有很多不管用的解决方案, 本文意在给出更有效的解决办法,并初步探究其原因 正文 在对话框中插入文本框是十分常见的需求 通常我 ...
- Android 初次进入默认不弹出软键盘
[遇到问题] 初次进入某个界面时,当页面中有EditText ,会自动聚焦并弹出软键盘. [解决方法] getWindow().setSoftInputMode(WindowManager.Layou ...
- Android EditText弹出软键盘实现页面标题头不动,软键盘弹出在编辑框下面
为了实现EditText编辑的时候弹出软键盘标题头不动,底部编辑框,上移在这总结: RelativeLayout在弹出软键盘的时候先寻找android:layout_alignParentBottom ...
- android延时弹出软键盘
searchEditView.setFocusable(true); searchEditView.setFocusableInTouchMode(true); searchEditView.requ ...
- EditText 默认不获取焦点,弹出软键盘布局变形解决方案
关于弹出软键盘布局变形解决方案: 在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan&qu ...
- AppCompatActivity 去掉标题栏和EditText弹出软键盘遮住输入框问题
1. AppCompatActivity去掉标题栏 此处除掉标题栏,需要注意一点,AppCompactActivity是继承自Activity.然而,AppCompactActivity据查看网上资料 ...
随机推荐
- 百度地图中使用mouseover事件获取经纬度时无法拿到鼠标所在位置的经纬度。
用百度2.0的话使用mousemove 鼠标在地图区域移动过程中触发此事件.mouseover参数e中没有point参数
- CentOS安装pip并修改源为豆瓣源
使用yum进行安装 yum install python-pip 若出现 No package python-pip available. 则解决方法如下: yum -y install epel-r ...
- ubuntu下安装谷歌浏览器
deb 是 Debian Linux 的安装格式,在 ubuntu 中同样可以使用.要安装 deb 安装包,需要使用 dpkg这个终端命令,命令格式如下: $ sudo dpkg -i <pac ...
- Jquery动态绑定事件处理函数 bind / on / delegate
1.bind方法绑定的事件处理函数不会应用到后来添加到DOM中的新元素.比如你在用bind给页面元素绑定事件之后,又新添加了一些与之前绑定过事件的元素一样的DOM元素,但是这些事件并不能在新的DOM元 ...
- Codeforces - 675D 可持久化Treap 树形操作
题意:模拟二叉树的构造过程,给出\(n\)个节点,每次从根插入,小于当前节点转到左儿子,否则右儿子,输出第\([2,n]\)个节点的父亲的权值 直接手动模拟会被链式结构T掉 网上找了下发现二叉树的性质 ...
- ZOJ - 1539 记忆化搜索
注意不要仅搜DP(1e7),因为这不是线性的 #include<iostream> #include<algorithm> #include<cstdio> #in ...
- 小数据池 is 和 == ,以及再谈编码
一.小数据池 1.id() 小数据池针对的是:int ,str,boo(都是不可变的数据类型) (1)如果是在py文件中写的字符串,几乎都是缓存的 (2)在黑窗口里写的机会都不会缓存 (3)不同的解释 ...
- web 页面 验证码 实现
1. 前台页面代码: 页面刷新时会自动请求 ${pageContext.request.contextPath}/yanzheng?yz=&time=-1111 这个action <f ...
- c# datagridview 相关操作。
string[] newRow = {"long","d","b"}; Gridview.Rows.Insert(Gridview.Rows ...
- ibatis配置文件中的XML解析错误The content of elements must consist of well-formed character data or markup.
在检查过所有的标签名都没有问题的情况下. xml中的小于号属于非法字符. SQL语句中则可能需要小于号,此时就需要用<![CDATA[ ]]>将小于号包裹,如此不会被xml解析器解析. ...