Reputation: 1202
The problem i'm facing is, that when the SearchView gets the focus, the parent ActionBar enlarges nearly to the top of the keyboard (like in the screenshot below). The effect only occures if both, the android:fitsSystemWindow
attribute of the Toolbar and the android:windowTranslucentStatus
style property are set to true. If one of them is false, the problem doesn't exist anymore.
What am i doin wrong? Did i miss any configuration?
I have the following simple layout in my activity:
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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="match_parent"
android:clickable="true"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimaryDark"
android:fitsSystemWindows="true"
android:height="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<ScrollView
android:id="@+id/search_result_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
My styles.xml looks like this:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
The menu_main.xml looks like this:
<menu 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"
tools:context=".MainActivity">
<item
android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_search"
android:title="@string/search_button"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView"/>
</menu>
Upvotes: 1
Views: 125
Reputation: 396
Did you try to limit the toolbar's height like
<android.support.v7.widget.Toolbar
...
android:layout_height="?attr/actionBarSize" />
? Instead of using wrap_content
?
(?attr/actionBarSize
causes the system to choose the standard toolbar height for the current configuration, e.g. 56dp for portrait on mobile phone)
Upvotes: 2