Taimur Ayaz
Taimur Ayaz

Reputation: 312

Move toolbar up when keyboard shown

In my app i have created a toolbar which sticks at the bottom of the screen now I want to move the toolbar above keyboard whenever the keyboard is show. I have tried the following ways but it didn't work

Tried this:

android:windowSoftInputMode="stateVisible|adjustResize"

and this

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

This is my layout file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent"         android:layout_height="fill_parent">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="133dp"
        android:gravity="center_vertical|top"
        android:textColor="@color/white"
        android:textSize="32sp"
        android:id="@+id/evmainText"
        android:inputType="textNoSuggestions"
        android:background="@android:color/transparent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" 
    />
    <include layout="@layout/text_toolbar" />
</RelativeLayout>

and here's the toolbar file

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textFormatToolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_alignParentBottom="true"
    android:minHeight="?attr/actionBarSize"
    android:background="@drawable/toolbar_back_text"
/>

I want to displsy toolbar like this

enter image description here

Upvotes: 0

Views: 1705

Answers (4)

AnT
AnT

Reputation: 891

Thanks to this answer, I was able to make this happens by:

1/ Add this attribute to the activity in AndroidManifest.xml

android:windowSoftInputMode="stateVisible|adjustResize"

2/ Add this attribute to your toolbar

android:windowActionBarOverlay="true"

Upvotes: 0

Vicky Mahale
Vicky Mahale

Reputation: 1229

I think its helf ful to you:

To enable adjustResize add android:fitsSystemWindows="true" in your activity's parent layout

Upvotes: 0

ShutterSoul
ShutterSoul

Reputation: 2621

Try with this

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Upvotes: 0

Aitor Viana
Aitor Viana

Reputation: 933

I have done this in the past with a button bar but through the AndroidManifest. Try adding to the manifest, in the activity that contains the toolbar, the following:

<activity android:windowSoftInputMode="adjustResize">
    <!-- Something else -->
</activity>

Hope it helps.

Upvotes: 1

Related Questions