1、android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
stateUnchanged:B的Activity設置了該屬性,A的Activity時軟鍵盤是什麼狀態,那麼到B的Activity就是什麼狀態。
stateAlwaysVisible:Activity的跳轉順序是A-->B-->C,假如B設置了該屬性,那麼從A跳到B,B的軟鍵盤處於顯示 狀態。從C後退到B,B的軟鍵盤又處於顯示狀態。
stateVisible:Activity的跳轉順序是A-->B-->C,假如B設置了該屬性,那麼從A跳到B,B的軟鍵盤處於顯示 狀態。從C後退到B,B的軟鍵盤處於隱藏狀態。
stateHidden:都隱藏。
stateAlwaysHidden:都隱藏。
adjustResize:只會把被遮蓋的EditText往上的部分頂上去,能執行OnSizeChangedListenner接口的
onSizeChange方法。
adjustPan:把整個頁面都頂上去。
2、登錄輸入框新的做法:
重寫最外層佈局RelativeLayout的onSizeChange方法,目的是監聽軟鍵盤的狀態。只要RelativeLayout的大小發生變化,系統就會調用其onSizeChange方法。
通過內部接口的方式,回調onSizeChange方法。
MainActivity
XML佈局:
<com.example.inputmodedemo.InputModeRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/inputRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6E6E6"
tools:context=".LoginActivity" >
<ImageView
android:id="@+id/login_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="85dp"
android:background="@drawable/login_avatar" />
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/login_avatar"
android:layout_marginTop="5dp" >
<RelativeLayout
android:id="@+id/rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/login_input_bg" >
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@null"
android:hint="用戶名"
android:inputType="text"
android:paddingLeft="20dp"
android:paddingTop="6dp"
android:singleLine="true"
android:textSize="18sp" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/username"
android:background="@null"
android:hint="密碼"
android:inputType="textPassword"
android:paddingLeft="20dp"
android:paddingTop="6dp"
android:singleLine="true"
android:textSize="18sp" />
</RelativeLayout>
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@id/rl"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:background="@drawable/login_button_xml"
android:text="登錄"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</RelativeLayout>
<Button
android:id="@+id/forgetPassword"
android:layout_width="90dp"
android:layout_height="35dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="30dp"
android:layout_marginLeft="15dp"
android:background="@drawable/login_register_xml"
android:text="忘記密碼"
android:textColor="@drawable/login_text_color"
android:textSize="16sp" />
<Button
android:id="@+id/registerButton"
android:layout_width="90dp"
android:layout_height="35dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="30dp"
android:layout_marginRight="15dp"
android:background="@drawable/login_register_xml"
android:text="註冊"
android:textColor="@drawable/login_text_color"
android:textSize="16sp" />
</com.example.inputmodedemo.InputModeRelativeLayout>
效果圖: