EditText android:windowSoftInputMode 属性之旅

来源:互联网 发布:java守护线程的作用 编辑:程序博客网 时间:2024/05/21 09:14

 当前Activity Edit获得焦点时,怎么设置不弹出键盘:

  android:windowSoftInputMode="stateHidden|adjustPan"
在Mainifest中对应的Activity设置这样的属性,这样软键盘就不会弹出来。

但是此时底部若有布局,会被软盘覆盖,这是为何呢?

"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并不会调整大小,由此可见,底部的bottom不会被顶上去。我们看看另外一个属性:

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

如果该窗口内有可以滑动的组件,那么这个窗口将会调整大小,而且这个属性是默认的,也就是说:

  android:windowSoftInputMode="stateHidden"
我这样设置属性和

 android:windowSoftInputMode="adjustUnspecified|stateHidden"
效果是一样的。我们写一个布局试一试:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_second"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:fitsSystemWindows="false"   ><ScrollView    android:layout_width="match_parent"    android:layout_height="wrap_content">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="vertical">        <ImageView            android:id="@+id/image"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginTop="20dp"            />    <EditText        android:id="@+id/work_cirle_edit1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_below="@id/image"        android:minHeight="100dp"        android:layout_marginLeft="15dp"        android:textSize="18sp"        android:gravity="top"        android:maxLength="140" />    <EditText        android:id="@+id/work_cirle_edit2"        android:layout_below="@+id/work_cirle_edit1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:minHeight="100dp"        android:layout_marginLeft="15dp"        android:textSize="18sp"        android:gravity="top"        android:maxLength="140" />    <EditText        android:id="@+id/work_cirle_edit3"        android:layout_below="@+id/work_cirle_edit2"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:minHeight="100dp"        android:layout_marginLeft="15dp"        android:textSize="18sp"        android:gravity="top"        android:maxLength="140" />    <EditText        android:id="@+id/work_cirle_edit4"        android:layout_below="@+id/work_cirle_edit3"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:minHeight="100dp"        android:layout_marginLeft="15dp"        android:textSize="18sp"        android:gravity="top"        android:maxLength="140" />    <EditText        android:id="@+id/work_cirle_edit5"        android:layout_below="@+id/work_cirle_edit4"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:minHeight="100dp"        android:layout_marginLeft="15dp"        android:textSize="18sp"        android:gravity="top"        android:maxLength="140" />    </LinearLayout></ScrollView>   <include       layout="@layout/bottom"       android:layout_height="wrap_content"       android:layout_width="match_parent"       android:layout_alignParentBottom="true"       /></RelativeLayout>
这里,用ScrollView包裹几个EditText 和ImageView,我们运行起来发现:



OK,解决了。

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小米5x忘记了屏保锁屏密码怎么办 htc手机锁屏密码忘了怎么办 苹果7手机解锁密码忘了怎么办 魅族7plus锁屏密码忘了怎么办 捡到苹果手机不知道id密码怎么办 平板不知道id地址和密码怎么办 红米1s刷机变砖了怎么办 车玻璃被鞭炮炸了黑印子怎么办 出轨的事被家人知道后道处传怎么办 村霸霸占土地弱势村民该怎么办? 户户通没有插卡位置信息改变怎么办 出现重大污染天气时企业该怎么办 电子税务句注册后未绑定企业怎么办 报税的时候PIN码忘了怎么办 购房合同丢失开发商不给补怎么办 租赁合同丢了房东不退押金怎么办 小孩不愿意喝奶粉爱喝乳酸菌怎么办 长安通不记名卡丢了怎么办 农村电表箱里的开关坏了怎么办 建行手机银行登录密码忘了怎么办 手机银行登入密码忘记了怎么办 邮政手机银行登录密码忘了怎么办 建设手机银行登入密码忘记了怎么办 浪琴机械表秒针走的快怎么办 雷达晶萃陶瓷表镀金掉色怎么办 做信息稿部分人员没拍到照片怎么办 二建条件不够考后审核怎么办 学校官网的教务系统忘记密码怎么办 已参加两次高考失败还想复读怎么办 我高考失利想补习学藉怎么办 本科毕业证上是1寸照片怎么办 老婆父母不给户口本迁户口怎么办 深圳夫妻投靠双方再婚的网上怎么办 老人档案丢了要继承公证怎么办 农民把户口迁入城市后宅基地怎么办 离婚了再婚带孩子在上海上学怎么办 上班几天被公司辞退不发工资怎么办 在单位工作被领导边缘化该怎么办 退休人员户口迁到外地退休金怎么办 招工表填写和实际的有误怎么办 招工时档案年龄有人为改动怎么办