自定义AlertDialog的写法和弹出软键盘和覆盖状态栏
来源:互联网 发布:unity3d xlua编程 编辑:程序博客网 时间:2024/06/05 16:22
自定义AlertDialog的写法一般有二种:
方法1
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(),0);
- 自定义AlertDialog的写法和弹出软键盘和覆盖状态栏
- 自定义的AlertDialog获取软键盘和editext中的内容
- 自定义AlertDialog中的EditText无法弹出软键盘的解决
- android中AlertDialog包含EditText时弹出键盘(dia和软键盘同时弹出)
- AlertDialog自定义布局中有editText,不能弹出软键盘
- 自定义alertdialog,中有edittext不能弹出软键盘,解决
- 关于android软键盘弹出挤压VIEW和覆盖View的问题
- android 自定义View在弹出的软键盘之上,以及测量软键盘高度和监听软键盘状态
- android 自定义View在弹出的软键盘之上,以及测量软键盘高度和监听软键盘状态
- 自定义AlertDialog里的EditText不能弹出软键盘的解决
- 自定义的AlertDialog里面点击EditText的时候软键盘不能弹出
- AlertDialog 自定义布局 以及 EditText 无法弹出软键盘的解决
- 解决在自定义AlertDialog中EditText无法弹出软键盘的问题
- AlertDialog自动弹出软键盘
- 腾讯互动直播1.8解决软键盘覆盖输入框和监听软键盘弹出关闭
- 监听软键盘的隐藏和弹出
- 监听软键盘的收起和弹出
- Android软键盘的弹出和隐藏
- 初识android设计模式—MVP
- SQL 语句字典
- Apple Pay 技术分享_陈hong_鑫
- 第七周项目一 顺序环形队列算法库
- raknet在Linux下的编译
- 自定义AlertDialog的写法和弹出软键盘和覆盖状态栏
- 第七周 项目六——停车场
- 3-3 构造函数的调用(高级)
- tomcat 建立虚拟目录
- Android中view和surfaceview的区别
- <jsp:include page="" flush=""> 标签传参
- linux工作队列机制
- GitHub入门到上传本地项目
- Android网络请求库 - Say hello to Volley