3

This is my first question here, after 2 hours of searching a similar case I couldn't find one therefor this post.

The problem is that I have an activity with a toolbar (v7 support toolbar) and a navigation drawer. This all works perfectly. The main activity has a fragment container, where I put different fragments (via the navigation drawer). Everything worked perfectly until I added a EditText to a fragment. When I select the EditText to input some text the softkeyboard is shown and the toolbar resizes untill the bottom is aligned with the softkeyboard (The actual height increases), I can not yet post images so I hope this is detailed enough. The fragment without input selected is displayed normally. The EditText is actually underneath the softKeyboard (at least the selection indicator can be seen there).

this is the layout file from the mainactivity:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/main_color_500">


    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="0dp"
            android:paddingRight="0dp"
            android:paddingTop="0dp"
            android:paddingBottom="0dp"
            android:orientation="vertical"
            tools:context="com.joost.smartplanner.MainFragmentActivity">

            <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/main_color_500"
                android:fitsSystemWindows="true"
                android:elevation="4dp"
                android:id="@id/app_bar"
                app:theme="@style/CustomToolbarStyle">

            </android.support.v7.widget.Toolbar>

            <FrameLayout
                android:id="@+id/mainFragmentContainer"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="@color/grey_100"
                android:padding="@dimen/zero_padding"
                android:gravity="top"
                android:orientation="horizontal"
                android:focusable="true">

            </FrameLayout>
        </LinearLayout>

        <fragment
            android:id="@+id/fragment_navigation_drawer"
            android:layout_width="@dimen/nav_drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:layout="@layout/fragment_navigation_drawer"
            android:name="com.joost.smartplanner.NavigationDrawerFragment" />

    </android.support.v4.widget.DrawerLayout>

</LinearLayout>

The fragment containing the editText:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fragment_bg_white"
    android:focusable="true"
    tools:context="com.joost.smartplanner.CreateEventFragment">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/create_event_scrollview">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/divider"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"/>

            <!-- Event name part -->
            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:imeOptions="flagNoExtractUi"
                android:hint="Event name"
                android:padding="8dp"
                android:ems="8"
                android:focusable="true"
                android:clickable="true"
                android:id="@+id/editText" />


        </LinearLayout>
    </ScrollView>
</LinearLayout>

And at last the toolbar initiation code in the MainActivity onCreate:

//Toolbar initiation
        toolbar  = (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
        getSupportActionBar().setTitle("");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        toolbar.setNavigationOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {

            }
        });
        toolbar.inflateMenu(R.menu.menu_main);

One thing that I tried to remove this problem is to set a fixed height for the toolbar, instead of the wrap_content value. This partially fixes the problem that the toolbar stays the same height but the icons inside the toolbar disappear, and in my opinion hard-coding a height that normally works fine is not the right solution.

Joost
  • 33
  • 5

1 Answers1

3

The issue you are seeing here is related to the android:fitSystemWindows="true" attribute in your toolbar.

Take a look at Android appcompat toolbar stretches when searchview gets focus. It seems that if you are using that property the parent view should also have android:fitSystemWindows="true" set.

Community
  • 1
  • 1
Ertyguy
  • 666
  • 4
  • 13
  • After an hour extra searching I found the same thread, just now. Thanks! – Joost Jan 25 '15 at 16:50
  • @Ertyguy This is my layout xml file http://pastebin.com/ZL4t5iuV, Could you please let me know where I need to use the **android:fitSystemWindows="true"** attribute. I was confused and where I use it, still the toolbar is getting hidden when my autocompleteTextview gains focus, i.e it is pushing the tool bar out from the screen – KK_07k11A0585 Aug 26 '15 at 14:21
  • @KK_07k11A0585In android:id="@+id/container_toolbar" LinearLayout – Smeet Apr 25 '16 at 11:22
  • 1
    android:fitSystemWindows="true" does not exist. Did you spell it correctly? – Mitch Aug 16 '19 at 22:09