【问题标题】:Styling toolbar in Android applicationAndroid 应用程序中的样式工具栏
【发布时间】:2017-03-18 04:38:10
【问题描述】:

活动:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.andre.myapplication.MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        style="@style/ToolbarTheme">



    </android.support.v7.widget.Toolbar>

</LinearLayout>

styles.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
        <item name="android:textColor">@android:color/white</item>
    </style>

</resources>

但我在工具栏上仍然有黑色标题。为什么?

【问题讨论】:

标签: android android-toolbar styling


【解决方案1】:

您好尝试将 textColor 直接设置到工具栏。如果它有效,那么主题中发生了一些奇怪的事情

【讨论】:

  • toolbar.setTitleTextColor(0xFFFFFFFF); 工作正常。
  • 是的,那也可以..但它只会改变标题颜色:)
【解决方案2】:
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

当我想要工具栏中的白色标题时,这对我有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-11
    • 2015-07-28
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多