我在爲我的Android
應用程序非常惱人的問題掙扎。 我創建了一個Activity
註冊到我的應用程序。Android - 拼圖佈局我的應用程序,當虛擬鍵盤可見
這是Activity
xml文件:
<?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_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="myapplication.MainActivity">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="?attr/actionBarTheme"
android:minHeight="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/appTitleBar"
android:elevation="4dp">
<TextView
android:text="@string/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toolbarText"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="?android:attr/textColorPrimaryInverse" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="?attr/actionBarTheme"
android:minHeight="?attr/actionBarSize"
android:id="@+id/activityTitleBar"
android:layout_below="@+id/appTitleBar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:elevation="4dp">
<TextView
android:text="@string/signinActivityTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="?android:attr/textColorPrimaryInverse" />
</android.support.v7.widget.Toolbar>
<TextView
android:text="Welcome. bla bla bla bla bla bla bla bla bla bla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/activityTitleBar"
android:layout_centerHorizontal="true"
android:layout_marginTop="57dp"
android:id="@+id/textView3"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textAlignment="center" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="96dp"
android:id="@+id/editText3"
android:hint="password" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:layout_below="@+id/editText3"
android:layout_alignRight="@+id/editText3"
android:layout_alignEnd="@+id/editText3"
android:layout_marginTop="49dp"
android:id="@+id/editText4"
android:hint="confirm" />
<Button
android:text="SIGN IN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="22dp"
android:id="@+id/button2"
android:layout_alignRight="@+id/editText4"
android:layout_alignEnd="@+id/editText4"
android:layout_alignLeft="@+id/editText4"
android:layout_alignStart="@+id/editText4" />
</RelativeLayout>
正如你可以看到ת我用兩個Toolbars
(我已經選擇了一個NoActionBar
主題),一個用於應用程序的名稱,一個用於Activity
標題。
然後我放置了一個TextView
,其中包含一個歡迎消息和應用程序的介紹。
最後,存在形式的符號,兩個EditText
(對於密碼和密碼確認)和一個Button
該提交密碼以在以後處理組成。
在這裏,它是如何在 「正常狀態」 顯示爲:
這個,反而是程序在虛擬鍵盤上:
這裏是問題:
第一個問題是,工具欄消失。我不想要它。 第二個問題是,我希望所有的表單(兩個編輯文本和Button
)必須在鍵盤上方。相反,只有第一個編輯文本在上面。 此外歡迎TextView
必須消失。
在實踐中,我想我的應用程序是這樣的,當虛擬鍵盤了起來:
我試着用
<activity android:windowSoftInputMode="adjustResize">
包裝你的形式在''並保持'adjustResize',我想你會得到你在找什麼。否則,Android需要通過移動整個頁面來適應空間不足(因爲它不可滾動)。但是你仍然可以在專注的EditText下找到鍵盤。我見過的一些應用程序(請參閱Chase銀行應用程序)是,它們將以浮動對話形式存在,並保持內容最小化,以便保證按鈕和編輯文本的高於KB –
ElliotM