android软键盘的用法总结
1.软键盘的显示原理
软键盘其实是一个Dialog。InputMethodService为我们的输入法创建了一个Dialog,并且对某些参数进行了设置,使之能够在底部
或者全屏显示。当我们点击输入框时,系统会对当前的主窗口进行调整,以便留出相应的空间来显示该Dialog在底部,或者全屏。
2.活动主窗口调整
Android定义了一个属性windowSoftInputMode, 用它可以让程序控制活动主窗口调整的方式。我们可以在配置文件AndroidManifet.xml中对Activity进行设置。这个属性的设置将会影响两件事情:
1>软键盘的状态——隐藏或显示。
2>活动的主窗口调整——是否减少活动主窗口大小以便腾出空间放软键盘或是否当活动窗口的部分被软键盘覆盖时它的内容的当前焦点是可见的。
故该属性的设置必须是下面列表中的一个值,或一个“state…”值加一个“adjust…”值的组合。在任一组设置多个值,各个值之间用|分开。
"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时,软键盘被隐藏。
"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
currentfocus 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.
它不被指定是否该Activity主窗口调整大小以便留出软键盘的空间,或是否窗口上的内容得到屏幕上当前的焦点是可见的。系统将自动选择这些模式中一种
主要依赖于是否窗口的内容有任何布局视图能够滚动他们的内容。如果有这样的一个视图,这个窗口将调整大小,这样的假设可以使滚动窗口的内容在一个较小的区
域中可见的。这个是主窗口默认的行为设置。也就是说,系统自动决定是采用平移模式还是压缩模式,决定因素在于内容是否可以滚动。
"adjustResize":
(压缩模式)The activity's main window is always resized to make room for the
soft keyboard on screen. 当软键盘弹出时,要对主窗口调整屏幕的大小以便留出软键盘的空间。
"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.
该Activity主窗口并不调整屏幕的大小以便留出软键盘的空间。相反,当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容
的部分。这个通常是不期望比调整大小,因为用户可能关闭软键盘以便获得与被覆盖内容的交互操作。。
3.侦听软键盘的显示隐藏
有时候,借助系统本身的机制来实现主窗口的调整并非我们想要的结果,我们可能希望在软键盘显示隐藏的时候,手动的对布局进行修改,以便使软键盘弹出时更加美观。这时就需要对软键盘的显示隐藏进行侦听。
我们可以借助软键盘显示和隐藏时,对主窗口进行了重新布局这个特性来进行侦听。如果我们设置的模式为压缩模式,那么我们可以对布局的onSizeChanged函数进行跟踪,如果为平移模式,那么该函数可能不会被调用。
4.EditText默认不弹出软件键盘
方法一:
在AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden
例如:<activity android:name=".Main"
android:label="@string/app_name"
android:windowSoftInputMode="adjustUnspecified|stateHidden"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
方法二:
让EditText失去焦点,使用EditText的clearFocus方法
例如:EditText edit=(EditText)findViewById(R.id.edit);
edit.clearFocus();
方法三:
强制隐藏Android输入法窗口
例如:EditText edit=(EditText)findViewById(R.id.edit);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
5.EditText始终不弹出软件键盘
例:EditText edit=(EditText)findViewById(R.id.edit);
edit.setInputType(InputType.TYPE_NULL);
android软键盘的用法总结的更多相关文章
- 关于android软键盘enter键的替换与事件监听
android软键盘事件监听enter键 软件盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有 normal,actionUnspecified,actionNo ...
- 完美解决android软键盘监听
最近在做应用性能调优,发现在一个包含有输入框的Activity中,当软键盘弹出的时候,如果直接finish掉此Activity,那么在返回到上一个Activity时,界面的渲染会由于软键盘没有及时的收 ...
- android软键盘enter键
enter键,回车键,电脑键盘上enter键就有多种响应.android软键盘也不例外 你在EditText上输入以后,想在下一行输入框输入,可能需要去点击下一行输入框,让它获取焦点,也可能要隐藏软键 ...
- Android软键盘弹出,覆盖h5页面输入框问题
之前我们在使用vue进行 h5 表单录入的过程中,遇到了Android软键盘弹出,覆盖 h5页面 输入框 问题,在此进行回顾并分享给大家: 系统:Android 条件:当输入框在可视区底部或者偏下的位 ...
- DownEditTextView【自定义Edittext对Android 软键盘向下的监听】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 记录自定义EditText控件实现监听软键盘隐藏事件的功能.基本上和参考资料相同. 效果图 代码分析 自定义EditText子 ...
- Android软键盘事件imeOptions响应
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 在android发开过程中,有时候需要对EditText的软键盘进行监听. 当点击软键盘回车位置按键的时候,需要实现 完成.前进.下 ...
- Android软键盘的隐藏显示、事件监听的代码
把开发过程中重要的一些内容片段做个珍藏,如下资料是关于Android软键盘的隐藏显示.事件监听的内容,应该是对小伙伴们有所用途. public class ResizeLayout extends L ...
- android软键盘弹出引起的各种不适终极解决方案
android软键盘弹出引起的各种不适终极解决方案 以下描述如何解决ListView高度小于0时出现的UI问题. 创建RelativeLayout的子类TxrjRelativeLayout publi ...
- Android 软键盘弹出,界面整体上移
在做搜索功能的时候,点击搜索框,搜索框获取焦点,键盘弹出:现在问题出来了,android软键盘弹出的时候,android整个界面上移,布局被挤压,很难看:要解决这个问题,我们需要用到 windowSo ...
随机推荐
- opencart 百度登录和百度钱包支付插件 响应式适应pc/mobile
OpenCart(http://www.opencart.com/,http://www.opencartchina.com/)是国外著名的开源电子商务系统, 优势在于前台界面的设计非常适合欧美购物者 ...
- adodb配置与使用
=========================================php100:80:ADODB PHP数据库万能引擎类 ADODB PHP数据库介绍与特点 ADODB 是一种兼容的各 ...
- C#使用字符串分割字符串
我们都会用字符分割字符串: string[] recvArr = recv.Split(';'); 如果用字符串分割呢?下面: string[] sArray = Regex.Split(recv, ...
- 解决类型“System.Web.UI.UpdatePanel”不具有名为“Gridview”的公共属性,
类型“system.web.ui.updatepanel” 不具有名为“XXX”的公共属性,其实原因很简单.就是少了一个<ContentTemplate></ContentTempl ...
- the design of everyday things
Design principles: Conceptual models Feedback Constraints Affordances All are important. This is wha ...
- Contest 20141027 总结
这次考试主要问题出在第一题,由于考试期间没有看清题意,少看了一句 “a=A/1e9" 导致在考试结束最后5分钟发现时修改过于匆忙,改出问题了.另外,这道题同时告诉我long double 在 ...
- Android 如何自定义EditText 下划线?
项目要求: 笔者曾经做过一个项目,其中登录界面的交互令人印象深刻.交互设计师给出了一个非常作的设计,要求做出包含根据情况可变色的下划线,左侧有可变图标,右侧有可变删除标志的输入框,如图 记录制作过程: ...
- 截断WM_SYSCOMMAND的SC_CLOSE命令(VC与Delphi双版本)
WM_SYSCOMMAND - 系统命令消息,当点击最大化按钮,最小化按钮,关闭按钮等.都会收到这个消息.常用于窗口关闭时提示用户处理.WPARAM - 具体的命令,例如 关闭 SC_CLOSELPA ...
- mysql 海量数据的存储和访问解决方案
第1章 引言 随着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大型的互 联网应用,每天几十亿的PV无疑对数据库造成了相当高的负载.对于系统的稳定性和扩展性造成了极大的 ...
- 15个值得开发人员关注的jQuery开发技巧和心得
在这篇文章中,我们将介绍15个让你的jQuery更加有效的技巧,大部分关于性能提升的,希望大家能够喜欢! 1. 尽量使用最新版本的jQuery类库 jQuery项目中使用了大量的创新.最好的方法来提高 ...