[英]Toolbar shifts up, when soft keyboard appears
我想讓我的活動布局在鍵盤出現時調整大小,但同時保持其工具欄位置不變。 到目前為止,當我單擊編輯文本並出現鍵盤時,所有屏幕都向上移動。
鍵盤出現后,工具欄不再可見:
我想將鍵盤保持在原位並將圖像移到其下方。 我不能只在清單中指定: android:windowSoftInputMode="adjustNothing"
,因為當鍵盤出現時,編輯文本將不再可見。
到目前為止,我使用以下代碼:
在 AndroidManifest.xml 中:
android:windowSoftInputMode="adjustPan|stateHidden"
在布局中:
<?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:background="@android:color/white"
android:clickable="true"
android:fitsSystemWindows="true"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="studentplanner.mobile.yardi.com.studplan.presentation.activities.PersonalInformationActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_and_button_height"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:elevation="4dp"
android:background="@color/main">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/personal_information_text"
android:textColor="@android:color/white"
android:textSize="@dimen/medium2_text_size" />
</android.support.v7.widget.Toolbar>
<ImageView
android:id="@+id/background_container"
android:layout_width="match_parent"
android:layout_height="@dimen/extra_large5_dimen"
android:layout_below="@+id/toolbar"
android:scaleType="center"
android:src="@drawable/userbackground" />
...
歡迎任何幫助!
在 AndroidManifest.xml 中添加 android:windowSoftInputMode="adjustResize" 解決問題。
<activity
android:name=".MainActivity"
android:label="@string/activity_main"
android:windowSoftInputMode="adjustResize">
</activity>
<item name="android:windowTranslucentStatus">true</item>
在styles.xml
添加android:fitsSystemWindows="true"
在你活動的父布局,並添加android:windowSoftInputMode="adjustResize"
清單中
樣式文件
<item name="android:windowTranslucentStatus">true</item>
並添加
android:fitsSystemWindows="true"
在您的活動 ParentLayout 中
我有同樣的問題。
在處理片段時,我將 isScrollContainer 放在框架布局中,它解決了所有鍵盤問題。
<FrameLayout android:id="@+id/container_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="true"/>
這就是我所需要的。
但是,如果您希望基於每個片段,那么通過在 onCreateView 片段回調中將容器設置為滾動容器來執行此操作:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_type_barcode, container, false);
container.setScrollContainer(true);
return rootView;
}
嘗試將ScrollView
作為父布局。 它有助於在ScrollView
內調整視圖的大小。
<RelativeLayout ...
<Toolbar...
</Toolbar>
</RelativeLayout>
<ScrollView ..
// your views
</ScrollView>
將 android:windowSoftInputMode="adjustPan" 添加到 AndroidManifest 中的活動。 那應該解決它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.