android中的EditText的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31743309/article/details/78837438

一.android:windowSoftInputMode属性详解

【1】stateUnspecified:软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置
【2】stateUnchanged:当这个activity出现时,软键盘将一直保持在上一个activity里的状态,无论是隐藏还是显示
【3】stateHidden:用户选择activity时,软键盘总是被隐藏
【4】stateAlwaysHidden:当该Activity主窗口获取焦点时,软键盘也总是被隐藏的
【5】stateVisible:软键盘通常是可见的
【6】stateAlwaysVisible:用户选择activity时,软键盘总是显示的状态
【7】adjustUnspecified:默认设置,通常由系统自行决定是隐藏还是显示
【8】adjustResize:该Activity总是调整屏幕的大小以便留出软键盘的空间
【9】adjustPan:当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分

二.EditText的使用

需求:模仿ios的输入框效果,在键盘弹出来输入的时候,布局除去标题栏整体向上滑动

这里写图片描述

如果用ScrollView将中间的布局包裹,而底部的提交评价的view设置layout_alignParentBottom为ture,最后会被软键盘顶上来
最后只有将底部的view放在ScrollView包裹的LinearLayout里面,值得注意是:

  • 1.ScrollView只能包裹一个子布局
  • 2.当ScrollView的子布局想填满ScrollView时,使用”match_parent”是不管用的,必需为ScrollView设置:android:fillViewport=”true”。

然后将面试评价的布局设置成自增长就行了,这样底部的提交评价view就可以显示在屏幕最底部了

布局代码:

  • manifest:
 <activity
    android:name=".view.activity.InterviewAssessActivity"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustResize|stateHidden" />
  • layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="com.recruit.cymobi.view.activity.InterviewAssessActivity">

    <com.recruit.cymobi.view.widget.TitleBarView
        android:id="@+id/titleBar"
        style="@style/TitleBarDefault"
        app:TitleBar_center_text="@string/interview_assess_title"
        app:TitleBar_left_Drawable="@drawable/icon_back" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/titleBar"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            ...

            ...
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginTop="4dp"
                android:layout_weight="1"
                android:orientation="vertical"
                android:paddingBottom="10dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="10dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/interview_assess"
                    android:textColor="@color/c_333333"
                    android:textSize="16sp" />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="160dp"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/bg_edit_resume"
                    android:gravity="top"
                    android:hint="@string/interview_assess_des"
                    android:padding="10dp"
                    android:textColorHint="#bcbcbc"
                    android:textSize="13sp" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/ll_comit_assess"
                android:layout_width="match_parent"
                android:layout_height="52dp"
                android:background="@color/white"
                android:orientation="horizontal"
                android:paddingBottom="5dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="5dp">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@null"
                    android:drawableLeft="@drawable/icon_anonymous_no"
                    android:gravity="center"
                    android:padding="13dp"
                    android:text="@string/anonymous"
                    android:textColor="@color/c_333333"
                    android:textSize="14sp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_button_finish"
                    android:gravity="center"
                    android:text="@string/commit_assess"
                    android:textColor="@color/white"
                    android:textSize="16sp" />

            </LinearLayout>

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

猜你喜欢

转载自blog.csdn.net/qq_31743309/article/details/78837438