【问题标题】:Change the text color of the toolbar overview更改工具栏概览的文本颜色
【发布时间】:2017-05-12 00:46:44
【问题描述】:

我找不到如何在 Android 上更改概览工具栏的文本颜色..:

我试过这个:

android:theme="@style/AppTheme"

<style name="AppBlankTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppBlankTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">true</item>
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:textColorSecondary">@android:color/white</item>
</style>

我想将标题(“Sharezone”)和概览工具栏的关闭按钮的颜色更改为白色。

谢谢。

-------------- 编辑 --------- ----------------------

经过很多失败的解决方案,这是我的完整代码:

style.xml

<style name="AppBlankTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme" parent="AppBlankTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:textColorTertiary">@color/grey_300</item>
</style>

AndroidManifest.xml

<application
    ...
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        ...
        android:theme="@style/AppTheme">
    </activity>
</application>

这是我在 Activity 中使用的工具栏:

<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
    android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary">
    <TextView
        android:id="@+id/toolbar_app_name"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/app_name"
        android:textSize="30sp"
        android:gravity="center_horizontal|center_vertical"
        android:textColor="@color/grey_300"/>
</android.support.v7.widget.Toolbar>

【问题讨论】:

标签: java android android-actionbar toolbar


【解决方案1】:

这是因为Theme.这是你在你的风格中设置的 style name="AppBlankTheme" parent="Theme.AppCompat.Light.DarkActionBar"

请使用这个主题

style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"

现在您应用的深色主题将被移除

【讨论】:

  • 如果您还有任何问题请告诉我@user3185672
  • 仍然无法正常工作。我使用其他代码元素编辑帖子。无论如何感谢您的回答@ghanshyam-sharma
【解决方案2】:

您可以通过 XML 执行此操作,如果您的活动称为 MainActivity 转到 res/layout/activity_main,转到设计并按下/选择操作栏,然后转到右侧的属性并选择 titleTextColor 并更改为所需颜色。

在这里选择颜色:

【讨论】:

    【解决方案3】:

    #. 看来你的themes 没问题。在AndroidManifest.xml 文件中,将AppTheme 应用到您想要的Activity

    AndroidManifest.xml

        <activity
            android:name=".YourActivity"
            android:theme="@style/AppTheme" />
    

    #.如果您在布局中使用Toolbar XML,那么您可以通过编程方式更改其title 颜色:

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar)
    toolbar.setTitleTextColor(Color.WHITE);
    

    更新:

    根据您更新的问题,您似乎正在使用自定义Toolbar。要更改标题"Sharezone" 颜色,您必须更改TextView (toolbar_app_name) 的background 颜色。

    <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary">
    
        <TextView
            android:id="@+id/toolbar_app_name"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/app_name"
            android:textSize="30sp"
            android:gravity="center_horizontal|center_vertical"
            android:textColor="#FFFFFF"/>
    </android.support.v7.widget.Toolbar>
    

    希望对你有帮助~

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      相关资源
      最近更新 更多