2017-08-24 97 views
0

我有一個活動使用自定義Toolbar溢出菜單更改自定義工具欄佈局

<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> 

它看起來像這樣的預覽:

enter image description here

但它看起來像這樣的設備上:

enter image description here

看起來溢出菜單正在改變佈局。有沒有辦法解決?

+0

您是否嘗試過將SearchView Maxwidth設置爲'(Integer.MAX_VALUE)'? – Abhi

回答

1

好像一些類似的問題已經被問沒有答案: How to properly add custom view to the toolbar?

相反,我只是把搜索視圖下面工具欄,而不是在它。我匹配了背景顏色。

<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

使用AppBarLayout將是另一個解決方案 - 如果您希望隱藏標題或用戶星星滾動時搜索,它們就會派上用場。 – reVerse

相關問題