2

I want to make my activity layout resize when keyboard appears, but at the same time keep its toolbar position unchanged. So far all the screen shifts up, when I click on the edit text and the keyboard appears.

Before keyboard appears:

After keyboard appears, the toolbar isn't visible anymore:

enter image description here

I would like to keep the keyboard in its place and shift below it the image. I can't just specify in the manifest: android:windowSoftInputMode="adjustNothing" , because the edit text will not be visible anymore, when the keyboard appears.

So far, I use the following code:

In AndroidManifest.xml:

android:windowSoftInputMode="adjustPan|stateHidden"

In layout:

 <?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" />

...

Any help is welcomed!

Community
  • 1
  • 1

6 Answers6

0

Adding android:windowSoftInputMode="adjustResize" in AndroidManifest.xml solve the problem.

<activity
        android:name=".MainActivity"
        android:label="@string/activity_main"
        android:windowSoftInputMode="adjustResize">
 </activity>
King of Masses
  • 18,405
  • 4
  • 60
  • 77
0

<item name="android:windowTranslucentStatus">true</item> in styles.xml

add android:fitsSystemWindows="true" in your activity's parent layout and add android:windowSoftInputMode="adjustResize" in manifest

Mohd Saquib
  • 580
  • 4
  • 14
  • android:windowSoftInputMode="adjustResize" This didn't solve my problem, because the keyboard overshadows the edit text. true have just made the Android system toolbar translucent, but didn't affect application toolbar. – Ghiurutan Alexandru Aug 11 '17 at 10:57
0

styles file

<item name="android:windowTranslucentStatus">true</item> 

and Add

android:fitsSystemWindows="true" 

in your activity ParentLayout

Harshit Trivedi
  • 764
  • 9
  • 33
0

i had the same issue.
when dealing with fragments i put isScrollContainer inside of the framelayout and it resolves all keyboard issues.

  <FrameLayout android:id="@+id/container_framelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:isScrollContainer="true"/>

thats all i needed.

but if you want ti on a per fragment bases then do this by setting your container to scrolling container in onCreateView fragment callback:

@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;
    }
j2emanue
  • 60,549
  • 65
  • 286
  • 456
0

Try ScrollView as a parent layout. It helps to resize views just inside the ScrollView.

<RelativeLayout ...
    <Toolbar...

    </Toolbar>
</RelativeLayout>

<ScrollView ..

// your views

</ScrollView>
sfmirtalebi
  • 370
  • 7
  • 16
0

Add android:windowSoftInputMode="adjustPan" to the activity in AndroidManifest. That should fix it.