下面是我的带菜单图标的导航抽屉的xml代码,我在下面的导航抽屉代码中加入了工具:导航视图。在加入 tools:navigation_view 之前,我的菜单图标是向屏幕右侧排列的。我的UI在加入navigation_view[][1[加入tools_navigation前我的UI的截图]]2
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item android:id="@+id/nav_account"
android:icon="@drawable/ic_account"
android:title="Account"/>
<item android:id="@+id/nav_walk"
android:icon="@drawable/ic_transfer_within_a_station_black_24dp"
android:title="Walk"/>
<item android:id="@+id/nav_train"
android:icon="@drawable/ic_subway"
android:title="Train"/>
</group>
<item android:title="Self">
<menu>
<item android:id="@+id/nav_byroad"
android:icon="@drawable/ic_time_to_leave_black_24dp"
android:title="By road"/>
<item android:id="@+id/nav_traffic"
android:icon="@drawable/ic_traffic_black_24dp"
android:title="Traffic"/>
</menu>
</item>
要想在抽屉中看到菜单的预览,你可以在下面的代码中添加 tools:openDrawer="start"
在xml中的抽屉布局组件中。
例子:
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">