参考:

  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)如何控制输入键盘的显示方式及参数表的更多相关文章

  1. GridLayout自定义数字键盘(两个EditText)

    功能说明: 适用于两个EditText输入框,并控制输入字符的长度,点击键盘中的"确定"按钮完成输入,点击"前一项"光标跳到前一个EditText 运行效果图如 ...

  2. Android Edittext 显示光标 获取焦点 监听焦点

    Edittext java 代码控制获取焦点 EditText mEditText = (EditText) findViewById(R.id.et); mEditText.setFocusable ...

  3. CSS基础选择器(选择器的优先级),CSS样式块( 长度/颜色/显示方式/文本样式),盒模型组成,盒模型-block,盒模型布局

    CSS基础选择器 (1)id选择器:   #       =>  标签拥有 id="user"  属性 <style> #user { width: 200px; ...

  4. android基本控件学习-----EditText

    EditText的讲解 一.<实例一>:用户登录 <?xml version="1.0" encoding="utf-8"?> < ...

  5. 自定义Visual Studio调试器中的对象显示方式

    你有没有盯着调试器窗口中的对象,并希望你可以通过其他类型的东西来查看这些对象?我当然有!扩展项目以确定每个人的身份可能会非常快速.理想情况下,通过特定的属性值快速定位它们会很棒.对我们来说幸运的是,V ...

  6. 进程控制之exec函数

    用fork函数创建子进程后,子进程往往要调用一种exec函数以执行另一个程序.当进程调用一种exec函数时,该进程执行的程序完全替换为新程序,而新程序则从其main函数开始执行.因为调用exec并不创 ...

  7. 大白话 Scala 控制抽象

    2019-04-14 关键字: Scala.Scala控制抽象.Scala高阶函数 本篇文章系笔者根据当前掌握的知识对 Scala 控制抽象的教材知识总结,不保证文章所述内容的绝对.完全正确性. 在 ...

  8. Linux网络编程学习(三) ----- 进程控制实例(第三章)

    本节主要介绍一个进程控制的实例,功能就是在前台或者后台接收命令并执行命令,还能处理由若干个命令组成的命令行,该程序命名为samllsh. 基本逻辑就是 while(EOF not typed) { 从 ...

  9. 基于FPGA的5寸LCD显示屏的显示控制

    基于FPGA的5寸LCD显示屏的显示控制 作者:lee神 1,图像处理基础知识 数字图像处理是指将图像信号转换成数字信号并利用计算机对其进行处理的过程.图像处理最早出现于 20 世纪 50 年代,当时 ...

随机推荐

  1. hdu - 3549 Flow Problem (最大流模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 Ford-Fulkerson算法. #include <iostream> #include ...

  2. SOJ 2818_QQ音速

    [题意]两只手,一次只能用一只手按一个键子(0,1,2,3),给出从i键到j键所需的消耗的体力,求依次按下一系列键子所需最小体力. [分析] 法一:开一个三维数组,分别记录移动到位置及左右手按的键子. ...

  3. Combinations(带for循环的DFS)

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  4. iis站点内存泄漏问题分析

    在一次上线过程中iis内存飙升,随后跟运维要到站点的dump文件,使用windbg分析了clr的内存分配,找到了问题的症结,先记录如下: 使用windbg加载dump文件 1.打开windbg,Fil ...

  5. Java发送邮件示例

    利用Java发送邮件示例: 1.发送QQ邮件 import java.util.Properties; import javax.mail.Message; import javax.mail.Mes ...

  6. Delphi 2007 的重构功能

    Move 移动 1.将选定的静态函数从一个类移动到另一个类 2.将选中的类或接口移动到其他单元 Extract Interface 抽取接口 将选定的函数抽取到一个新的接口中 Extract Supe ...

  7. 009 NAT

    static nat r1(config)#ip nat inside source static 192.168.1.2 10.0.0.2 r1(config)#int f0/0 r1(config ...

  8. Cardboard虚拟现实开发初步(二)

    Google Cardboard 虚拟现实眼镜开发初步(二) Cardboard SDK for Unity的使用 上一篇文章作为系列的开篇,主要是讲了一些虚拟现实的技术和原理,本篇就会带领大家去看一 ...

  9. django 名词解释

    1) 什么是slug http://stackoverflow.com/questions/427102/what-is-a-slug-in-django 如上链接红色部分就是slug,它就是链接的最 ...

  10. C语言之基本算法25—牛顿迭代法求方程近似根

    //牛顿迭代法! /* ============================================================ 题目:用牛顿迭代法求解3*x*x*x-2*x*x-16 ...