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. [Microsoft] 微软技术平台的Cloud Building平台AppVeyor

    Link: http://www.tuicool.com/articles/uMBZba http://www.appveyor.com/ 随着云技术的不断完善,基于云的应用越发丰富起来.AppVey ...

  2. EasyUI学习笔记(一)EasyUI入门

    一.EasyUI下载 EasyUI官方下载地址:http://www.jeasyui.com/download/index.php,目前最新的版本是:jquery-easyui-1.7.2 解压后得到 ...

  3. bzoj 1005: [HNOI2008]明明的烦恼 树的prufer序列+万进制

    题目传送门 思路: 这道题需要前置知识prufer编码,这篇博客对prufer编码和这道题的分析写的很好. 这里主要讲一些对大数阶乘的分解,一个办法当然是用高精度,上面这篇博客用的是java,还有一个 ...

  4. C# 判别系统版本以及Win10的识别办法

    首先得知道操作系统和主次版本的对应关系 我们可以用Environment.OSVersion来判断当前操作系统 && Environment.OSVersion.Version.Min ...

  5. 【Python】探测网站是否可以访问

    首先贴上简陋的python脚本 #coding:utf-8 import urllib,linecache for line in linecache.updatecache('url.txt'): ...

  6. 【研究】CVE-2015-1635-HTTP.SYS远程执行代码漏洞(ms15-034)

    1.1.1  漏洞描述 在2015年4月安全补丁日,微软发布的众多安全更新中,修复了HTTP.sys中一处允许远程执行代码漏洞,编号为:CVE-2015-1635(MS15-034 ).利用HTTP. ...

  7. PostgreSQL精简命令:

    dos命令行连接PostgreSQL: . 接入PostgreSQL数据库: psql -h IP地址 -p 端口 -U 用户名 -d 数据库名 . 输入数据库密码 C:\Users\admin\De ...

  8. 接口隔离原则(Interface Segregation Principle)ISP

    using System; using System.Collections.Generic; using System.Text; namespace InterfaceSegregationPri ...

  9. roboframework-ride运行案例时报 Error 267 错误问题

    偶然间碰到这个问题,检查下路径是否有中文,如有中文换成英文试试. (ps:通常自己创建的中文路径也是可以的,我的案例是从Linux环境中创建拷贝过来的,可能导致案例路径编码问题)

  10. 网络连接和初始HTTP请求

    浏览器检索网页,先从URL开始,使用DNS确定IP地址,再用基于TCP和HTTP协议连接到服务器,请求相关的内容,得到相应,浏览器解析并呈现到屏幕上.服务器响应后,浏览器响应不会同时全部到达,会陆续到 ...