[英]Soft Keyboard Hides Actionbar
我有一個簡單的活動,文本視圖后跟兩個編輯文本。 當我開始輸入時,軟鍵盤會向上推動布局並隱藏操作欄,我將無法選擇/復制/粘貼文本。
我的活動如下:
當我開始輸入時,操作欄會被隱藏,就像這樣 - 更重要的是,請注意,即使文本突出顯示,也會丟失正常的復制粘貼欄:
我該怎么做才能確保操作欄不隱藏?
在我的活動清單中,我使用的是adjustPan。 我不想使用adjustResize。
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
我的活動在這里:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/navigation_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/app_theme.app_bar_overlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/app_theme.popup_overlay" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_margin"
android:fillViewport="true"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="@android:color/darker_gray"
android:text="My holiday story here." />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/activity_margin" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/gap_normal"
android:gravity="top"
android:text="My Holiday in Europe" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="top"
android:text="My holiday story is blah blah blah blah blah blah blah blah blah..." />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
<com.magicparcel.app.mysampleapp.ui.CustomNavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/navigation_drawer_header"
app:itemIconTint="@color/app_grey_500"
app:menu="@menu/drawer_main" />
</android.support.v4.widget.DrawerLayout>
嘗試在工具欄中添加app:layout_collapseMode="pin"
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="@style/app_theme.popup_overlay" />
並在editText中啟用復制/粘貼Set android:textIsSelectable="true"
在https://developer.android.com/guide/topics/text/copy-paste.html上查看更多內容
步驟1 :從每個視圖中刪除fitsSystemWindow
屬性,並將其添加到清單中的activity標記中。
第2步 : app:layout_behavior="@string/appbar_scrolling_view_behavior"
從線性布局中刪除此行。 這是實際推動上面的操作欄的代碼。
這兩個步驟解決了我的問題,希望它也能幫到你。
在AppBarLayout中添加工具欄並添加AppBarOverLay和PopOverlay主題。
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
styles.xml
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.