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的写法和弹出软键盘和覆盖状态栏的更多相关文章

  1. Android开发禁止首次进入activity弹出软键盘,限制屏幕只能竖屏或者横屏展示

    作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 只需在在Manifest.xml中设定activity的属性为: android:windowSoft ...

  2. Android为TV端助力之弹出软键盘方式

  3. Android 显示Dialog的同时自动弹出软键盘;

    需求大致就是这样的:用户点击按钮弹出Dialog,Dialog中有输入框,然后Dialog弹出后要自动弹出软键盘:(如果让用户自己手动点击输入框再弹出软键盘的话,用户体验太差了): 好的,需求大致就是 ...

  4. (原)android的alertdialog中加入edittext但是不弹出软键盘等问题的解决与原因

    摘要:alertdialog中加入edittext但是不弹出软键盘等问题网上有很多不管用的解决方案, 本文意在给出更有效的解决办法,并初步探究其原因 正文 在对话框中插入文本框是十分常见的需求 通常我 ...

  5. Android 初次进入默认不弹出软键盘

    [遇到问题] 初次进入某个界面时,当页面中有EditText ,会自动聚焦并弹出软键盘. [解决方法] getWindow().setSoftInputMode(WindowManager.Layou ...

  6. Android EditText弹出软键盘实现页面标题头不动,软键盘弹出在编辑框下面

    为了实现EditText编辑的时候弹出软键盘标题头不动,底部编辑框,上移在这总结: RelativeLayout在弹出软键盘的时候先寻找android:layout_alignParentBottom ...

  7. android延时弹出软键盘

    searchEditView.setFocusable(true); searchEditView.setFocusableInTouchMode(true); searchEditView.requ ...

  8. EditText 默认不获取焦点,弹出软键盘布局变形解决方案

    关于弹出软键盘布局变形解决方案: 在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan&qu ...

  9. AppCompatActivity 去掉标题栏和EditText弹出软键盘遮住输入框问题

    1. AppCompatActivity去掉标题栏 此处除掉标题栏,需要注意一点,AppCompactActivity是继承自Activity.然而,AppCompactActivity据查看网上资料 ...

随机推荐

  1. Matlab2015 双目相机自动标定

    标定步骤 调出标定工具箱 在命令行输入stereoCameraCalibrator,出现如下界面: 勾选相应的选项 然后将上面的“Skew”.“Tangential Distortion”以及“3 C ...

  2. PHP7 关于变量的基本判断

    刚学 PHP ,一些基础还不太牢固,边实践边记录. about NULL $class_name = null; 语句结束后,$class_name 是空,没有,什么都没有的“空”.用 is_null ...

  3. Mutation and Iteration

    avoid mutating a list as you are iterating over it 代码: def remove_dups(L1,L2): for e in L1: if e in ...

  4. 精神AC合集 2018.4.3

    UESTC炸了,先把看似十分OK(只是过了样例)的代码贴上,修复好后再交上去 594 #include<iostream> #include<algorithm> #inclu ...

  5. 【研究】Tomcat远程代码执行漏洞(CVE-2017-12615)

    一.Tomcat远程代码执行漏洞(CVE-2017-12615) 1.1       实验环境 操作机:windows 10                         IP:192.168.1. ...

  6. (转)博弈 SG函数

    此文为以下博客做的摘要: https://blog.csdn.net/strangedbly/article/details/51137432 ---------------------------- ...

  7. GreenPlum 大数据平台--远程访问-->gpadmin客户端

    一,客户端连接 01,配置文件说明 在master节点的$MASTER_DATA_DIRECTORY(这个是配置的环境变量:/greenplum/data/master/gpseg-1)/pg_hba ...

  8. (转)DB2 restart database命令的作用总结

    DB2 restart database命令的作用总结 原文:https://blog.csdn.net/qingsong3333/article/details/62049039 信息中心对于RES ...

  9. React.js 小书 Lesson10 - 组件的 state 和 setState

    作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson10 转载请注明出处,保留原文链接和作者信息. state 我们前面提到过,一个组件的显示形态 ...

  10. Win10内置应用恢复初始状态

    和Win8/Win8.1相同,Win10也内置了很多默认Windows应用,比如计算器.天气.人脉.Groove音乐.电影和电视.邮件和日历.Edge浏览器等.一般情况下,这些应用不会有太大的问题,但 ...