我的Android进阶之旅------>Android中android:windowSoftInputMode的用法

简介:  面试题:如何在显示某个Activity时立即弹出软键盘? 答案:在AndroidManifest.xml文件中设置标签的android:windowSoftInputMode属性可以在显示Activity时立即弹出当前输入法的软键盘(不管是否有获得焦点的空间)。

 面试题:如何在显示某个Activity时立即弹出软键盘?


答案:在AndroidManifest.xml文件中设置<activity>标签的android:windowSoftInputMode属性可以在显示Activity时立即弹出当前输入法的软键盘(不管是否有获得焦点的空间)。

设置为:android:windowSoftInputMode="stateVisible|adjustPan"   代码如下:

   <activity
            android:name=".RingstonActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:windowSoftInputMode="stateVisible|adjustPan"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >

启动程序,进入RingstonActivity就弹出了当前的输入法,本人手机上装的是搜狗输入法


=================================中文大义如下=================================
attributes:android:windowSoftInputMode
活动的主窗口如何与包含屏幕上的软键盘窗口交互。这个属性的设置将会影响两件事情:
1> 软键盘的状态——是否它是隐藏或显示——当活动(Activity)成为用户关注的焦点。
2> 活动的主窗口调整——是否减少活动主窗口大小以便腾出空间放软键盘或是否当活动窗口的部分被软键盘覆盖时它的内容的当前焦点是可见的。
它的设置必须是下面列表中的一个值,或一个”state…”值加一个”adjust…”值的组合。在任一组设置多个值——多个”state…”values,例如&mdash有未定义的结果。各个值之间用|分开。例如: <activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >
在这设置的值(除"stateUnspecified"和"adjustUnspecified"以外)将覆盖在主题中设置的值


下面是这些值的含义:

含义
stateUnspecified 软键盘的状态(是否它是隐藏或可见)没有被指定。系统将选择一个合适的状态或依赖于主题的设置。这个是为了软件盘行为默认的设置。
stateUnchanged 软键盘被保持无论它上次是什么状态,是否可见或隐藏,当主窗口出现在前面时。
stateHidden 当用户选择该Activity时,软键盘被隐藏——也就是,当用户确定导航到该Activity时,而不是返回到它由于离开另一个Activity。
stateAlwaysHidden 软键盘总是被隐藏的,当该Activity主窗口获取焦点时。
stateVisible 软键盘是可见的,当那个是正常合适的时(当用户导航到Activity主窗口时)。
stateAlwaysVisible 当用户选择这个Activity时,软键盘是可见的——也就是,也就是,当用户确定导航到该Activity时,而不是返回到它由于离开另一个Activity。
adjustUnspecified 它不被指定是否该Activity主窗口调整大小以便留出软键盘的空间,或是否窗口上的内容得到屏幕上当前的焦点是可见的。系统将自动选择这些模式中一种主要依赖于是否窗口的内容有任何布局视图能够滚动他们的内容。如果有这样的一个视图,这个窗口将调整大小,这样的假设可以使滚动窗口的内容在一个较小的区域中可见的。这个是主窗口默认的行为设置。
adjustResize 该Activity主窗口总是被调整屏幕的大小以便留出软键盘的空间。
adjustPan  该Activity主窗口并不调整屏幕的大小以便留出软键盘的空间。相反,当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分。这个通常是不期望比调整大小,因为用户可能关闭软键盘以便获得与被覆盖内容的交互操作。
欧阳鹏 http://blog.csdn.net/ouyang_peng



========================================官网介绍如下========================================

语法如下:

<activity
android:windowSoftInputMode=["stateUnspecified",
                                       "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible", "adjustUnspecified",
                                       "adjustResize", "adjustPan"] > 


android:windowSoftInputMode
How the main window of the activity interacts with the window containing the on-screen soft keyboard. The setting for this attribute affects two things:
  • The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention.
  • The adjustment made to the activity's main window — whether it is resized smaller to make room for the soft keyboard or whether its contents pan to make the current focus visible when part of the window is covered by the soft keyboard.

The setting must be one of the values listed in the following table, or a combination of one "state..." value plus one "adjust..." value. Setting multiple values in either group — multiple "state..." values, for example — has undefined results. Individual values are separated by a vertical bar (|). For example:

<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >

Values set here (other than "stateUnspecified" and "adjustUnspecified") override values set in the theme.

V alue 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.
"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.
"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.
"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.

INTRODUCED IN: API Level 1 for all attributes except for  noHistory and  windowSoftInputMode, which were added in API Level 3.

                            ====================================================================================

  作者:欧阳鹏  欢迎转载,与人分享是进步的源泉!

  转载请保留原文地址http://blog.csdn.net/ouyang_peng

====================================================================================

 


相关文章
|
2月前
|
Java Android开发 数据安全/隐私保护
安卓逆向 -- IDA基本用法
安卓逆向 -- IDA基本用法
41 0
|
8月前
|
Android开发
Android 中选项菜单(Option menu)的用法
Android 中选项菜单(Option menu)的用法
77 0
|
7月前
|
编解码 网络协议 Android开发
Android平台RTMP|RTSP直播播放器功能进阶探讨
很多开发者在跟我聊天的时候,经常问我,为什么一个RTMP或RTSP播放器,你们需要设计那么多的接口,真的有必要吗?带着这样的疑惑,我们今天聊聊Android平台RTMP、RTSP播放器常规功能,如软硬解码设置、实时音量调节、实时快照、实时录像、视频view翻转和旋转、画面填充模式设定、解码后YUV、RGB数据回调等:
104 0
|
8月前
|
Android开发
Android studio中的调试(Debug)按钮具体用法
Android studio中的调试(Debug)按钮具体用法
116 0
|
8月前
|
XML Android开发 数据格式
Android 动画之帧动画(也叫图片动画)的用法
Android 动画之帧动画(也叫图片动画)的用法
146 0
|
8月前
|
Android开发
Android 中String.format()的用法
Android 中String.format()的用法
54 0
|
8月前
|
Android开发
Android onActivityResult()的属性与用法
Android onActivityResult()的属性与用法
94 1
|
8月前
|
XML Android开发 数据格式
Android XML 布局基础(二)ID 用法
Android XML 布局基础(二)ID 用法
187 0
|
11月前
|
XML Android开发 数据格式
Android shape的用法详解
Android shape的用法详解
Android shape的用法详解
|
12月前
|
Web App开发 编解码 前端开发
Android | 音视频方向进阶路线及资源合集
但是系统相机和系统控件VideoView的局限性都是可定制型太差,系统相机的图像分辨率,视频码率以及VideoView的进度条等.
153 0