Reputation: 3084
I have a simple activity with a text view followed by two edit texts. When I start typing, the soft keyboard pushes layout up and hides the action bar, and I won't be able to select/copy/paste text.
My activity looks like this:
When I start typing, the action bar gets hidden, like this - and more importantly, note that the normal copy paste bar is missing even though a text is highlighted:
What can I do to make sure the action bar does not hide?
In my activity manifest I am using adjustPan. I do not want to use adjustResize.
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
My activity is here:
<?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>
Upvotes: 26
Views: 4426
Reputation: 4513
Step-1 : Remove fitsSystemWindow
attribute from each view and add it in the activity tag in the manifest.
Step-2 : app:layout_behavior="@string/appbar_scrolling_view_behavior"
Remove this line from your linear layout. This is the code which is actually pushing the actionbar above.
These two steps solved my problem, Hope it helps you too.
Upvotes: 2
Reputation: 7557
Add you Toolbar inside AppBarLayout and add AppBarOverLay and PopOverlay themes.
<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" />
Upvotes: 0
Reputation: 5865
Try by adding app:layout_collapseMode="pin"
in toolbar
<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" />
and for enable copy/paste in editText Set android:textIsSelectable="true"
look more on https://developer.android.com/guide/topics/text/copy-paste.html
Upvotes: 6