Android中使用NavigationView实现抽屉侧滑效果中Menu菜单栏设置

本文介绍如何在Android应用中设置NavigationView的字体大小及颜色,并提供设置默认选中项的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.Menu菜单栏中item字体大小设置:

a、在value/styles.xml中定义样式
<!--设置Menu中item的字体大小-->
    <style name="WindowTitle" parent="@android:style/TextAppearance">
        <item name="android:textSize">20sp</item>
    </style>
b、在使用NavigationView布局中设置使用此样式:
<android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:background="@drawable/background"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:itemTextAppearance="@style/WindowTitle"
        app:headerLayout="@layout/nav_header_main2"
        app:menu="@menu/activity_main_drawer"/>

2.Menu菜单栏中item字体颜色设置:

Resources resource=(Resources)getBaseContext().getResources();
ColorStateList csl=(ColorStateList)resource.getColorStateList(R.color.mywhite);
navigationView.setItemTextColor(csl);

3.设置MenuItem默认选中项

navigationView.getMenu().getItem(0).setChecked(true);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值