EditText(5)如何控制输入键盘的显示方式及参数表
参考:
https://developer.android.com/training/keyboard-input/visibility.html
1,进入Activity时,EditText就获得焦点并显示输入软键盘。
如果EditText所在的activity是Activity是主activity,那么以上行为是默认的,不是的话,要设置Activity的属性:
<application ... >
<activity
android:windowSoftInputMode="stateVisible" ... >
...
</activity>
...
</application>
注意,如果键盘是按键的,那么不显示键盘,只显示光标。
2,使用代码控制显示软键盘和焦点。
调用下面的方法就可让某个view可输入文本:
public void showSoftKeyboard(View view) {//指定想要输入键盘的view
if (view.requestFocus()) {//1,取得焦点
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);//2,用InputMethodManager显示键盘
}
}
关闭键盘不用代码,按回车或返回键后自动消失。
3,控制键盘与页面控件的布局方式,可让键盘不挡住页面上的控件并可以滚动等。如:
<activity android:name=".MainActivity"
android:windowSoftInputMode="stateVisible|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
4,详细的软键盘显示参数
<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >
Values set here (other than "stateUnspecified" and "adjustUnspecified") override values set in the theme.
| Value | Description |
|---|---|
"stateUnspecified" |
The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will choose an appropriate state or rely on the setting in the theme. This is the default setting for the behavior of the soft keyboard. 默认的显示方式,不指定参数。 |
"stateUnchanged" |
The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore. 按上次样式显示 |
"stateHidden" |
The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. 当进入到activity且eidt有焦点时,不显示键盘。 |
"stateAlwaysHidden" |
The soft keyboard is always hidden when the activity's main window has input focus. 总是不显示软键盘。 |
"stateVisible" |
The soft keyboard is visible when that's normally appropriate (when the user is navigating forward to the activity's main window). 显示软键盘 |
"stateAlwaysVisible" |
The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. 当进入或离开时activity时,一直显示软键盘。 |
"adjustUnspecified" |
It is unspecified whether the activity's main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the current focus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window's contents visible within a smaller area. This is the default setting for the behavior of the main window. |
"adjustResize" |
The activity's main window is always resized to make room for the soft keyboard on screen. Activity的主窗口会缩放,以让软键盘不挡住view。 |
"adjustPan" |
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window. |
This attribute was introduced in API Level 3.
EditText(5)如何控制输入键盘的显示方式及参数表的更多相关文章
- GridLayout自定义数字键盘(两个EditText)
功能说明: 适用于两个EditText输入框,并控制输入字符的长度,点击键盘中的"确定"按钮完成输入,点击"前一项"光标跳到前一个EditText 运行效果图如 ...
- Android Edittext 显示光标 获取焦点 监听焦点
Edittext java 代码控制获取焦点 EditText mEditText = (EditText) findViewById(R.id.et); mEditText.setFocusable ...
- CSS基础选择器(选择器的优先级),CSS样式块( 长度/颜色/显示方式/文本样式),盒模型组成,盒模型-block,盒模型布局
CSS基础选择器 (1)id选择器: # => 标签拥有 id="user" 属性 <style> #user { width: 200px; ...
- android基本控件学习-----EditText
EditText的讲解 一.<实例一>:用户登录 <?xml version="1.0" encoding="utf-8"?> < ...
- 自定义Visual Studio调试器中的对象显示方式
你有没有盯着调试器窗口中的对象,并希望你可以通过其他类型的东西来查看这些对象?我当然有!扩展项目以确定每个人的身份可能会非常快速.理想情况下,通过特定的属性值快速定位它们会很棒.对我们来说幸运的是,V ...
- 进程控制之exec函数
用fork函数创建子进程后,子进程往往要调用一种exec函数以执行另一个程序.当进程调用一种exec函数时,该进程执行的程序完全替换为新程序,而新程序则从其main函数开始执行.因为调用exec并不创 ...
- 大白话 Scala 控制抽象
2019-04-14 关键字: Scala.Scala控制抽象.Scala高阶函数 本篇文章系笔者根据当前掌握的知识对 Scala 控制抽象的教材知识总结,不保证文章所述内容的绝对.完全正确性. 在 ...
- Linux网络编程学习(三) ----- 进程控制实例(第三章)
本节主要介绍一个进程控制的实例,功能就是在前台或者后台接收命令并执行命令,还能处理由若干个命令组成的命令行,该程序命名为samllsh. 基本逻辑就是 while(EOF not typed) { 从 ...
- 基于FPGA的5寸LCD显示屏的显示控制
基于FPGA的5寸LCD显示屏的显示控制 作者:lee神 1,图像处理基础知识 数字图像处理是指将图像信号转换成数字信号并利用计算机对其进行处理的过程.图像处理最早出现于 20 世纪 50 年代,当时 ...
随机推荐
- 2.5 3-way quickSort
1.排序时,数组含有大量重复元素,应该使用哪种排序手段? (1)mergeSort:与数组的特征无关,比较次数总是在1/2NlgN~NlgN之间 (2)quickSort:当所有的元素全都相同的时候, ...
- Python基础之 一 补充
三元运算: 语法:result = 值1 if 条件 else 值2 当条件为真时,result = 值1 当条件为假时,result = 值2 进制: 二进制:01 八进制:01234567 十进制 ...
- SAP EP 设置Portal别名安全模式
Securing the Portal Alias Cookie Context We recommend that you set the portal alias cookie to be del ...
- Errors running builder 'JavaScript Validator' on
eclipse编译提示Errors running builder 'JavaScript Validator' on 解决方法见下图 去掉 'JavaScript Validator' 即可
- nodejs连接sqlserver
nodejs连接sqlserver http://blog.csdn.net/kkkkkxiaofei/article/details/31353091
- [React] Prevent Unnecessary Rerenders of Compound Components using React Context
Due to the way that React Context Providers work, our current implementation re-renders all our comp ...
- jQuery—— jQuery get方法+一般处理程序处理文本框内容
网上常常看到这种交互方式,当去一个站点注冊username的时候,假设文本框内没有输入数据,或者数据输入的内容格式不正确.就会将文本框变成红色来提示你输入的内容有误. 自己将这个文本框验证的方式改变了 ...
- Codeforces Round #271 (Div. 2) D. Flowers (递推 预处理)
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all kn ...
- C#如何使用右下角托盘图标notifyIcon
1 拖放一个NotifyIcon控件,并设置图标,还有显示的文字 2 双击这个控件,即当最小化了主窗体,然后双击这个右下角图标的时候,要显示主窗体(大部分程序的用户体验都是这样干的,比如QQ,双击 ...
- Ganglia API安装与使用
Ganglia监控本身没有提供API可供外部程序调用,只是依据ganglia监控的原理,能够通过分析gmetad的port的xml来直接获取metrics. Guardian已经在Github上公布了 ...