2017-08-24 4 views
0

Ich habe eine Aktivität mit einem benutzerdefinierten Toolbar:Überlauf Menü wechselt individuelle Toolbar Layout

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:elevation="4dp" 
     android:theme="@style/AppTheme" 
     app:contentInsetStart="0dp" 
     app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingBottom="8dp" 
      android:paddingLeft="8dp" 
      android:paddingRight="8dp" 
      android:paddingTop="8dp"> 

    < !-- More content, including search box --> 

     </RelativeLayout> 

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

Es ist wie diese in der Vorschau sieht:

enter image description here

Aber es sieht so aus auf dem Gerät :

enter image description here

Es scheint, als ob das Überlaufmenü das Layout ändert. Gibt es einen Weg dazu?

+0

Haben Sie versucht, die SearchView Maxwidity auf '(Integer.MAX_VALUE)' '? – Abhi

Antwort

1

Scheint wie einige ähnliche Fragen haben, ohne eine Antwort gefragt worden: How to properly add custom view to the toolbar?

Statt nur ich unten die Symbolleiste, um die Suche setzen, nicht in ihr. Ich habe die Hintergrundfarben angepasst.

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:theme="@style/AppTheme" 
     app:logo="@drawable/ic_restaurant_white_24px" 
     app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar" 
     app:title="@string/app_name" 
     app:titleMarginStart="24dp" 
     app:titleTextColor="@android:color/white"> 

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

    <FrameLayout 
     android:id="@+id/filter_bar_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/toolbar" 
     android:background="?attr/colorPrimary" 
     android:padding="12dp"> 
+0

Die Verwendung eines 'AppBarLayout' wäre eine andere Lösung - würde sich als nützlich erweisen, wenn Sie entweder den Titel oder die Suche ausblenden möchten, sobald der Benutzer scrollt. – reVerse