![](/img/trans.png)
[英]How to change item text color from a NavigationDrawer menu using styles.xml?
[英]How to change default Toolbar title text from @string/app_name to “”, but only changing styles.xml?
我有一个应用程序
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
在某些活动中,我在xml中手动添加ToolBar ,默认情况下包含@string/app_name标题文本。 我知道我可以调用setDisplayShowTitleEnabled(false)或类似的方法,但它不适合我。 我需要其他方式,例如在AppTheme中更改某些内容,以便默认情况下通过所有应用程序更改标题文本。 怎么做?
我添加的工具栏:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/colorAccent"
app:navigationIcon="@drawable/ic_default_nav_icon_white" />
您可以尝试创建一个新的布局文件并在其中添加工具栏代码。 见下面这是 layout_app_bar.xml 您可以在其中指定工具栏的标题。
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimary"
android:elevation="4dp"
app:title="WhateverName"
app:titleTextAppearance="@style/AppbarTitle"
app:titleTextColor="@color/colorWhite" />
然后在您的活动中,您可以像任何其他标签一样包含布局文件。 您可以在所有活动中使用工具栏的这个单一布局文件。
<LinearLayout>
<include
android:id="@+id/appbar"
layout="@layout/layout_app_bar" />
</LinearLayout>
我希望它对你有所帮助。 快乐编码!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.