android自定义dilog键盘,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开发禁止首次进入activity弹出软键盘,限制屏幕只能竖屏或者横屏展示

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

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据查看网上资料 ...

随机推荐

mui 下拉刷新

mui 下拉刷新 此文提供的是mui这种下拉刷新.悬浮于页面上,比较好用.

JS实现日程安排 日程安排插件

代码:

AjaxPro使用说明

转自:http://www.cnblogs.com/lexus/archive/2007/11/29/977281.html 目录 AjaxPro使用说明    1 目录    2 修改历史纪录    ...

设计模式之组合模式——Java语言描述

组合模式又叫做部分整体模式,适用于把一组相似的对象当作一个单一的对象.组合模式依据树形结构来组合对象,用来表示部分以及整体层次 介绍 意图 将对象组合成树形结构以表示"部分-整体" ...

SmartSql 介绍

介绍 SmartSql = MyBatis + Cache(Memory | Redis) + R/W Splitting +Dynamic Repository + Diagnostics .... ...

react-native-printer

react-native-printer A React Native Library to support USB/BLE/Net printer for Android platform Inst ...

读取excel 文件到datatable

上一篇文章介绍了将datatable 内容导出到excel 文件,这里介绍如何将一个excel 文件读取出来,并保持到datatable 中,实际这样的应用场景也是经常遇到的. 这里继续使用了Micr ...

stackoverflow愚人节彩蛋效果

效果如图所示: index.js /*! * Fairy Dust Cursor.js * - 90's cursors collection * -- https://github.com/thol ...

SDE在64位Server2008下Post启动服务失败官方解释

解决了一个SDE启动问题,在此记录一下 在server 2008 64位下安装完arcgis sde之后,Post启动服务,总是失败 查看SDE日志(etc目录下) DB_open_instance( ...

简单入门dos程序

--1.关机程序 注意:文件保存为.bat echo 晚安了,宝贝! @echo off shutdown -s -t exist --2.快捷/批量启动程序 title "程序系统启动&q ...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值