案例分析:
Android新啟動Activity,dialog或者其他窗體中中包含EditText, 新啟動的activity的焦點預設在EditText上,這時候android系統會自動彈出螢幕鍵盤。這會導致擠壓activity本來的界面,影響美觀。
解決方案:
強制讓父layout獲得焦點即可,請注意:
android:focusable="true"
android:focusableInTouchMode="true"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="56dp"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:gravity="center_vertical">
<ImageView android:src="@drawable/main_slogan"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_marginBottom="24dp"
android:layout_gravity="center_horizontal" />
<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<com.andreabaccega.widget.FormEditText
android:id="@+id/input_phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="fill_horizontal"
android:inputType="number"
android:hint="請輸入電話"
android:textAppearance="?android:attr/textAppearanceMedium"
whatever:emptyErrorString="請輸入電話!"
whatever:testType="phone"
/>
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Password"/>
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:padding="12dp"
android:text="登入"/>
<TextView android:id="@+id/link_signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:text="還沒有帳號? 註冊一個吧"
android:gravity="center"
android:textSize="16dip"/>
</LinearLayout>
</LinearLayout>

沒有留言 :
張貼留言