android - How can I put a SearchView inside of a ToolBar with a height set to wrap_content without it disappearing? -
i've noticed if place android.support.v7.widget.searchview
inside of android.support.v7.widget.toolbar
height set wrap_content
searchview
behaves strangely. appears fine @ first gains focus disappears , no longer takes space in layout. can resolved setting explicit height toolbar
i'm trying use wrap_content
because use-case requires toolbar
resize dynamically.
it might worth mentioning searchview
still functional after disappears. if add searchview.onquerytextlistener
searchview
can observe query text indeed being updated type. neither text nor other part of searchview
takes space in layout though , if force unobscured in layout still not visible.
this kind of seems bug in searchview
me. have more insight why it's happening or how work around it?
here's working example of issue:
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout 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:fitssystemwindows="true" tools:context="com.me.myactivity"> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingtop="@dimen/appbar_padding_top" android:theme="@style/apptheme.appbaroverlay"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorprimary" app:layout_scrollflags="scroll|enteralways" app:popuptheme="@style/apptheme.popupoverlay"> <android.support.v7.widget.searchview android:id="@+id/internalsearchview" app:queryhint="to..." android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" > </android.support.v7.widget.searchview> </android.support.v7.widget.toolbar> </android.support.design.widget.appbarlayout> </android.support.design.widget.coordinatorlayout>
it looks should work... have 2 suggestions.
- if doesn't interfere design goals, set
android:minheight="?attr/actionbarsize"
on toolbar. may desired anyway. - try setting
android:layout_height="48dp"
on searchview.
Comments
Post a Comment