java - Android:如何更改操作栏标题?

标签 java android

这是我的 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正在使用AppTheme.PopOverlay主题在 styles.xml 中定义文件。

目前工具栏上的标题设置为默认应用程序名称,我想更改标题,所以我已经尝试包含 <item name="android:text">@string/customtitle</item> AppTheme.PopOverlay 中的属性主题。没成功。

现在开始想知道,默认情况下标题是如何定义为应用程序名称的,以及如何更改它。

已添加 我想从这个问题中根本上找出的是,即使在 XML 文件、AndroidManifest.xml 或代码的任何部分中都没有定义标题,但默认情况下如何使用工具栏中的应用程序名称设置标题.

最佳答案

您可以通过两种方式更改标题:

以编程方式(在您的 Activity 中):

setTitle("Title");

XML(在您的 list 中):

<activity android:name=".SomeClass" android:label="Title" />  

要更改操作栏的字体,您可以考虑这篇文章:How to Set a Custom Font in the ActionBar Title?

关于java - Android:如何更改操作栏标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34070876/

相关文章:

java - 不要为 Spring Boot Actuator/health 端点显示磁盘空间和数据库

Java 在 VPS 上内存不足

android - Google Play 出现无效产品错误

android - 构建一个将连接到包含 SQL 数据库的服务器的 Android 应用程序。我应该怎么做?

java - 我是否需要为具有登录系统的 Web 应用程序实现 OAuth 服务器?

java - 控制语句: Why is my 'New Balance' change when I 'charge to credit' then 'pay credit' twice?

java - Java如何将功能代码转换为方法

Android Studio, ImageView ,

java - 再次调用fragment时是否可以恢复fragment UI中数据的状态?

android - sendUserActionEvent() 为空