windowsSoftInputMode 属性的理解和说明,如何实现输入软键盘时,向上移动一定距离

要想使布局向上移动,让输入法键盘向上移动

1.在AndroidManifest.xml文件中,添加一个属性

android:windowSoftInputMode="adjustPan|stateHidden"

 

 布局相关代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LL_rg"
    android:clipToPadding="false"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/login_color"
    android:orientation="vertical" >
 
<RelativeLayout 
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dp"
    android:layout_marginTop="200dp"
  	android:layout_width="match_parent"
    	android:layout_height="wrap_content"	    
    >
    <EditText
        android:id="@+id/rg_account"
        android:ems="30"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="填写注册账号"
        android:singleLine="true"
        android:maxLines="1"
        android:textSize="16sp"
        android:textColor="@color/white"
        android:textColorHint="@color/white" 
        android:drawableBottom="@drawable/edit_line"
        android:background="@null"
         />
   
 
    <EditText
        android:layout_below="@+id/rg_account"
        android:id="@+id/rg_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:textColor="@color/white"
        android:ems="30"
        android:hint="填写登陆密码"
        android:singleLine="true"
        android:maxLines="1"
        android:textSize="16sp"
        android:inputType="textPassword"
        android:textColorHint="@color/white" 
        android:drawableBottom="@drawable/edit_line"
        android:background="@null"
        />
    
    
    <EditText
        android:layout_below="@+id/rg_password"
        android:id="@+id/rg_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:textColor="@color/white"
        android:ems="30"
        android:hint="填写关联邮箱"
        android:singleLine="true"
        android:maxLines="1"
        android:textSize="16sp"
        android:inputType="textEmailAddress"
        android:textColorHint="@color/white" 
        android:drawableBottom="@drawable/edit_line"
        android:background="@null"
        />
    
     <Button
        android:id="@+id/register_bt"
        android:layout_below="@+id/rg_email"
    	android:layout_width="match_parent"
    	android:layout_height="40dp"
    	android:layout_marginTop="20dp"
    	android:textSize="16sp"
    	android:textColor="@color/login_color"
    	android:text="注册"
    	android:gravity="center"
    	android:background="@drawable/button_selector"     
         />
    </RelativeLayout>
</LinearLayout>


 

windowSoftInputMode属性设置值说明,可选属性如下。

<activity

android:windowSoftInputMode=["stateUnspecified",

                         "stateUnchanged", "stateHidden",

                         "stateAlwaysHidden", "stateVisible",

                         "stateAlwaysVisible","adjustUnspecified",

                         "adjustResize", "adjustPan" >

</activity>

windowSoftInputMode----活动的主窗口如何与包含屏幕上的软键盘的交互。

该属性主要影响以下两个事件

1.软键盘(是否隐藏),当前Activity(是否成为关注焦点)

2.Activity的主窗口调整(是否减少Activity主窗口大小以便腾出空间放软键盘或是否当Activity窗口的部分被软键盘覆盖时它的内容是否是当前焦点是可见的)

Key:

1.该属性值得设置必须是”state…”值或一个”state…”值加一个”adjust…”值的组合,各个值之间必须用|隔开;

2.AndroidManifest.xml文件中设置的值("stateUnspecified""adjustUnspecified")以外,将覆盖在主题中设置的值。

 

各属性解读

1."stateUnspecified" 

软键盘没有指定是否隐藏,系统将选择一个合适的状态或者根据主题的设置确定状态,这是对软键盘行为的默认设置;

2."stateUnchanged"

当主窗口出现时,无论软键盘上次是什么状态,是隐藏还是可见,都会被保持;

3."stateHidden"

当用户选择Activity(当用户导航到该Activity,而不是返回这个Activity,而是离开另一个Activity)时,软键盘被隐藏;: }/ N! p( a* M% W. b%m9 b# 

4."stateAlwaysHidden"

当该Activity主窗口获取焦点时软键盘总是被隐藏;

5."stateVisible"

软键盘是可见的,(当用户导航Activity主窗口时)

6."stateAlwaysVisible"

当用户选择这Activity时,软键盘是可见的当用户确定导航到Activity时,而不是返回到它而是离开另一Activity

7."adjustUnspecified"

被指定是否Activity主窗口调整屏幕大小以便留软键盘的足够空间,或窗口上的内容得到屏幕上当前的焦点是可见的。系统将自动选择这些模式中一种窗口的内容是否有任何布局视图能够滚动它们自己的内容。如果有这样的一个视图,这个窗口将调整大小,这样的假设可以使滚动窗口的内容在一个较小的区域中可见的。这是对主窗口默认的行为设置。

8."adjustResize"

Avtivity主窗口总是被调整屏幕的大小,以便留出软键盘的空间。

 

9."adjustPan"

Activity主窗口并不调整屏幕的大小以便留出软键盘的空间。反之,当前窗口的内容将自动移动以便当前焦点不被键盘覆盖和用户能总是看到输入内容的部分。这个设置不期望调整大小,因为用户可能关闭软键盘以便获得与被覆盖内容的交互操作。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值