参考:

  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. 常用生产环境的PHP安装参数

    ./configure --prefix=/usr/local/php5. --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/b ...

  2. Pull方式解析XML文件

    package com.pingyijinren.test; import android.content.Intent; import android.os.Handler; import andr ...

  3. Linux下Apache服务部署静态网站------网站服务程序

    文章链接(我的CSDN博客): Linux下Apache服务部署静态网站------网站服务程序

  4. CLR运行机制

    CLR编译器会将我们的代码编译成托管模块(中间IL语言和元数据),托管模块是一个标准的PE32执行文件,或者PE32+执行文件.但是CLR实际不和托管模块一起工作,他会将托管模块合并成程序集,程序集是 ...

  5. HDOJ 4259 Double Dealing

    找每一位的循环节.求lcm Double Dealing Time Limit: 50000/20000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. Hadoop 知识

    Map Reduce & YARN 简介 Apache Hadoop 是一个开源软件框架,可安装在一个商用机器集群中,使机器可彼此通信并协同工作,以高度分布式的方式共同存储和处理大量数据.最初 ...

  7. Tree Operations 打印出有向图中的环

    题目: You are given a binary tree with unique integer values on each node. However, the child pointers ...

  8. Android Toast小解

    简单介绍:Toast英文含义是吐司,在Android中.它就像烘烤机里做好的吐司弹出来,并持续一小段时间后慢慢消失. Toast也是一个容器,能够包括各种View,并承载着它们显示. Android中 ...

  9. Mybatis的配置文件和映射文件具体解释

    一.Mybatis的全局配置文件 1.SqlMapConfig.xml是mybatis的全局配置文件.配置内容例如以下: properties(属性) settings(全局配置參数) typeAli ...

  10. StringBuffer疑问

    为何结果为AB.B? public static void main(String[] args) { StringBuffer a=new StringBuffer("A"); ...