如何更改底部导航活动菜单布局文件的设计选项卡视图(tools:showIn)?

6
我只想将我的设计作为底部导航视图显示,因此我在 menu.xml 文件中尝试了以下设置:tools:showIn="bottom_navigation_view",但是对我的设计视图选项卡没有任何影响。
我不想要的菜单视图的图片:

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="bottom_navigation_view">

    <item
        android:id="@+id/navigation_home"
        android:icon="@drawable/ic_home_black_24dp"
        android:title="@string/title_home" />

    <item
        android:id="@+id/navigation_dashboard"
        android:icon="@drawable/ic_dashboard_black_24dp"
        android:title="@string/title_dashboard" />

    <item
        android:id="@+id/navigation_notifications"
        android:icon="@drawable/ic_notifications_black_24dp"
        android:title="@string/title_notifications" />

</menu>

请建议我一个适合的tools:showIn 值,使其能够正常工作。


尝试将其指向@layout/yourlayout而不是bottom_navigation_view - karan
我也遇到了同样的问题,但是是在 NavigationView 上。我尝试了 @KaranMer 说的方法,但是没有起作用。 - Just The Highlights
你可以使用 tools:showIn="navigation_view" 作为另一种选择。 - Zain
3个回答

0
将此代码添加到您的布局中,并替换menu的值。
<android.support.design.widget.BottomNavigationView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/windowBackground"
    android:theme="@style/AppTheme"
    app:menu="@menu/navigation"
    android:layout_gravity="start"
    android:id="@+id/navigation"
    />

是的,我做到了,但我也想在设计选项卡中将我的菜单/navigation.xml作为底部导航视图查看。我想要通过tools:showIn值来实现。 - Abhishek

0
 menu.xml folder should be created under res ⇒ menu folder.

android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.bottomnavigation.MainActivity">

<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="?android:attr/windowBackground"
    app:itemBackground="@color/bgBottomNavigation"
    android:foreground="?attr/selectableItemBackground"
    app:itemIconTint="@android:color/white"
    app:itemTextColor="@android:color/white"
    app:menu="@menu/navigation" />


0

试试这个

activity_layout.xml

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/colorPrimary"
    app:itemIconTint="@drawable/bottom_nav_colors"
    app:itemTextColor="@drawable/bottom_nav_colors"
    app:menu="@menu/bottom_navigation_items"/>

bottom_navigation_items.xml(菜单)

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
    android:id="@+id/action_home"
    android:icon="@drawable/ic_home_blue_48dp"
    android:title="Home" />
<item
    android:id="@+id/action_menu"
    android:icon="@drawable/ic_apps_black_24dp"
    android:title="Menu"
     />
<item
    android:id="@+id/action_msg"
    android:icon="@drawable/ic_chat_black_24dp"
    android:title="Message Inbox"
   />
</menu>

1
如果您能解释一下这是如何解决底部导航菜单中的设计预览未正确显示的问题,那将非常好。 - Just The Highlights

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接