我正在使用刚刚在I / O上显示的新材料组件。我能够创建一个底部应用栏,但菜单不显示搜索图标。相反,它只在溢出菜单中显示它。我能做错什么?
<com.google.android.material.bottomappbar.BottomAppBar
style="@style/Widget.MaterialComponents.BottomAppBar"
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
app:elevation="5dp"
android:elevation="5dp"
app:fabAttached="true"
app:fabCradleDiameter="0dp"
app:navigationIcon="@drawable/ic_bottom_bar_hamburger"
app:backgroundTint="@color/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:fabAlignmentMode="center"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
android:showAsAction="never" />
<item
android:title="@string/search"
android:id="@+id/search"
android:orderInCategory="100"
android:icon="@drawable/ic_search_black_24dp"
android:showAsAction="always" />
答案 0 :(得分:4)
res>>new>>android resource directory>>select menu in resource type
New Menu Resource file
,将其命名为bottom_bar_menu
bottom_bar_menu
app:menu="@menu/bottom_bar_menu"
中使用BottomBar
醇>
所以你最后的xmls会喜欢:
<com.google.android.material.bottomappbar.BottomAppBar
style="@style/Widget.MaterialComponents.BottomAppBar"
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
app:elevation="5dp"
android:elevation="5dp"
app:fabAttached="true"
app:fabCradleDiameter="0dp"
app:navigationIcon="@drawable/ic_bottom_bar_hamburger"
app:backgroundTint="@color/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:fabAlignmentMode="center"
app:menu="@menu/bottom_bar_menu"/>
在res>menu>bottom_bar_menu
中,将showAsAction
更改为always
或ifRoom
,为action_settings
添加一个图标并移除orderInCategory
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="always"
android:icon="" />
<item
android:title="@string/search"
android:id="@+id/search"
android:icon="@drawable/ic_search_black_24dp"
android:showAsAction="always" />
</menu>