【发布时间】:2015-12-03 16:13:34
【问题描述】:
这是我的 styles.xml 文件。
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary4</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark4</item>
<item name="colorAccent">@color/colorAccent2</item>
<item name="android:fontFamily">fonts/HelveticaNeue-Light.ttf</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.Widget" />
<style name="AppTheme.Widget.TextView" parent="android:Widget.Holo.Light.TextView">
<item name="android:fontFamily">fonts/HelveticaNeue-Light.ttf</item>
</style>
</resources>
这是包含工具栏的布局文件。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".HomeActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_home" />
</android.support.design.widget.CoordinatorLayout>
所以,toolbar 使用的是在styles.xml 文件中定义的AppTheme.PopOverlay 主题。
目前工具栏上的标题设置为默认应用名称,我想更改标题,所以我已经尝试在AppTheme.PopOverlay 主题中包含<item name="android:text">@string/customtitle</item> 属性。没用。
现在开始想,标题是如何默认定义为应用名称的,以及如何更改它。
已添加 我想从这个问题的根本上找到的是,即使在 XML 文件的任何部分、AndroidManifest.xml 或代码中都没有定义标题,默认情况下如何使用工具栏中的应用程序名称设置标题.
【问题讨论】:
-
您是否需要在 XML 中严格执行此操作,或者您是否可以使用以编程方式执行此操作的解决方案?
-
我更喜欢使用 XML,但我也想找出以编程方式实现它的方法。
-
如stackoverflow.com/questions/8607707/… 之前所述,您应该在询问之前进行搜索