我试图在Lollipop工具栏中设置文本样式。然而,无论我尝试什么,颜色总是来自应用程序" text_primary"样式项而不是样式我尝试用它覆盖它。
以下是一个例子。我试图让文字变白。
colors.xml:
<resources>
<color name="primary">#8BC34A</color>
<color name="primary_dark">#669900</color>
<color name="accent">#64DD17</color>
<color name="text_primary">#333</color>
<color name="text_secondary">#424242</color>
<color name="photo_tint">#424242</color>
<color name="toolbarTitleText">#fff</color>
<color name="toolbarActionMenuTextColor">#333</color>
<color name="toolbarTextColorSecondary">#fff</color>
</resources>
styles.xml:
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<item name="android:colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/text_primary</item>
<item name="android:textColor">@color/text_secondary</item>
<item name="android:navigationBarColor">@color/primary_dark</item>
</style>
<style name="ToolbarTheme" parent="Theme.AppCompat">
<item name="android:textColorPrimary">@color/toolbarTitleText</item>
<item name="android:textColorPrimaryInverse">@color/toolbarTitleText</item>
<item name="actionMenuTextColor">@color/toolbarActionMenuTextColor</item>
<item name="android:textColorSecondary">@color/toolbarTextColorSecondary</item>
</style>
</resources>
toolbar.xml
<android.support.v7.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="wrap_content"
android:background="?attr/colorPrimaryDark"
app:theme="@style/ToolbarTheme"
android:theme="@style/ToolbarTheme"
android:titleTextAppearance="@color/toolbarTitleText"
android:subtitleTextAppearance="@color/toolbarTitleText"
app:titleTextAppearance="@color/toolbarTitleText"
app:subtitleTextAppearance="@color/toolbarTitleText"
/>
正如您所看到的,我已经尝试了几种方法来应用&#34; ToolbarTheme&#34; toolbar.xml中的样式。然而,没有任何工作。
答案 0 :(得分:2)
固定。
更改&#34; Theme.AppCompat.Light&#34; to&#34; Theme.AppCompat.Light.DarkActionBar&#34;在styles.xml中,文本为白色。
答案 1 :(得分:1)
您可以为工具栏设置主题:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ActionBarThemeOverlay"
android:background="?attr/colorPrimaryDark" />
然后在你的styles.xml中:
<style name="ActionBarThemeOverlay" parent="">
<item name="textColorPrimary">#fff</item>
<item name="colorControlNormal">#fff</item>
<item name="colorControlHighlight">#3fff</item>
</style>