6 xml android navigation-drawer
我必须自定义我的导航抽屉,这是res/menu/activity_main_drawer.xml中代码的一部分
<item
android:title="Discover">
<menu>
<item
android:id="@+id/nav_qrcode"
android:icon="@drawable/read_qr"
android:title="QRCode" />
<item
android:id="@+id/favorite"
android:icon="@drawable/favorite"
android:title="favorite" />
</menu>
</item>
Run Code Online (Sandbox Code Playgroud)
这是res/layout/activity_home.xml中的布局
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="#B59154"
app:itemTextColor="#ffffff"
app:menu="@menu/activity_main_drawer" />
Run Code Online (Sandbox Code Playgroud)
我想为第一个项目分配背景颜色,我该怎么做?
"发现"是一个类别,其他项目是manù(可点击).
我不知道如何为我的"类别"分配不同的布局.
KDe*_*kar 11
你总是可以选择创建你的,custom layout所以你可以按照自己的方式为导航抽屉设计它.例如.
导航视图
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<include layout="@layout/lay_drawer_menu" />
</LinearLayout>
</ScrollView>
</android.support.design.widget.NavigationView>
Run Code Online (Sandbox Code Playgroud)
lay_drawer_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<TextView
android:id="@+id/txt1"
android:textcolor = "whatever you want"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Activities" />
<TextView
android:id="@+id/txt2"
android:textcolor = "whatever you want"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Add Detail"
android:textColor="@android:color/black" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
活动
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.txt1: {
drawerLayout.closeDrawers();
//your code.
}
break;
case R.id.txt2: {
drawerLayout.closeDrawers();
//your code.
}
break;
}
}
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助.
| 归档时间: |
|
| 查看次数: |
9838 次 |
| 最近记录: |