Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soft Keyboard Hides Actionbar

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:

Normal activity view

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:

Missing action bar and the copy/paste bar

What can I do to make sure the action bar does not hide?

  • I have tried some other tips from SO (such as using scroll view) but none worked.
  • The app is created using Android Studio 1.4.1 wizard with the Drawer Activity.
  • 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>
like image 469
henrykodev Avatar asked Sep 09 '25 22:09

henrykodev


1 Answers

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

like image 143
Uttam Panchasara Avatar answered Sep 12 '25 14:09

Uttam Panchasara