我想增加activity_main_drawer.xml里面项目的字体大小,这是导航抽屉菜单中显示的项目。我已经尝试通过添加android更改内部标记:textSize =“22dp”我还在style.xml文件中创建了“样式”
<style name="DrawerTextStyle" >
<item name="android:textColor">@color/colorPrimaryDark</item>
<item name="android:textSize">40dp</item>
<item name="android:textStyle">bold</item>
</style>
然后我申请activity_main_drawer.xml。但它没有生效。
<?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="navigation_view"
android:theme="@style/DrawerTextStyle">
<group android:checkableBehavior="single">
<item
android:id="@+id/author_nietzsche"
android:icon="@drawable/ic_person_black_48dp"
android:title="Friedrich Nietzsche" />
<item
android:id="@+id/author_rand"
android:icon="@drawable/ic_person_black_48dp"
android:title="Ayn Rand" />
<item
android:id="@+id/author_kant"
android:icon="@drawable/ic_person_black_48dp"
android:title="Immanuel Kant" />
<item
android:id="@+id/author_aurelius"
android:icon="@drawable/ic_person_black_48dp"
android:title="Marcus Aurelius" />
<item
android:id="@+id/author_descartes"
android:icon="@drawable/ic_person_black_48dp"
android:title="Rene Descartes" />
<item
android:id="@+id/author_schopenhauer"
android:icon="@drawable/ic_person_black_48dp"
android:title="Arthur Schopenhauer" />
<item
android:id="@+id/author_confucius"
android:icon="@drawable/ic_person_black_48dp"
android:title="Confucius" />
<item
android:id="@+id/author_russell"
android:icon="@drawable/ic_person_black_48dp"
android:title="Bertrand Russell" />
<item
android:id="@+id/author_sartre"
android:icon="@drawable/ic_person_black_48dp"
android:title="Jean-Paul Sartre" />
</group
</menu>
有些人建议在activity_main.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"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer">
</android.support.design.widget.NavigationView >
您必须应用此属性:
android:theme="@style/DrawerTextStyle"
到NavigationView
而不是菜单,
但首先将dp
改为sp
:
<style name="DrawerTextStyle" >
<item name="android:textColor">@color/colorPrimaryDark</item>
<item name="android:textSize">40sp</item>
<item name="android:textStyle">bold</item>
</style>