如何使用Material Design更改操作栏文本颜色?

huangapple go评论61阅读模式
英文:

How to change Actionbar text color using Material Design?

问题

I am using Material Design in my Android app and I want to change Actionbar text color and back button color.

This code is not working:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowContentOverlay">@null</item>
    <!-- <item name="android:textSize">3sp</item> -->
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/titleColor</item>
</style>

Is there anything else you need assistance with?

英文:

I am using Material Design in my Android app and I want to change Actionbar text color and back button color.

This code is not working:

    &lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.MaterialComponents.Light.DarkActionBar&quot;&gt;
    &lt;!-- Customize your theme here. --&gt;
    &lt;item name=&quot;colorPrimary&quot;&gt;@color/colorPrimary&lt;/item&gt;
    &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/colorPrimaryDark&lt;/item&gt;
    &lt;item name=&quot;colorAccent&quot;&gt;@color/colorAccent&lt;/item&gt;
    &lt;item name=&quot;android:windowContentOverlay&quot;&gt;@null&lt;/item&gt;
    &lt;!--&lt;item name=&quot;android:textSize&quot;&gt;3sp&lt;/item&gt;--&gt;
    &lt;item name=&quot;android:actionBarStyle&quot;&gt;@style/MyTheme.ActionBarStyle&lt;/item&gt;

&lt;/style&gt;

&lt;style name=&quot;MyTheme.ActionBarStyle&quot; parent=&quot;@android:style/Widget.Holo.Light.ActionBar&quot;&gt;
    &lt;item name=&quot;android:titleTextStyle&quot;&gt;@style/MyTheme.ActionBar.TitleTextStyle&lt;/item&gt;
&lt;/style&gt;

&lt;style name=&quot;MyTheme.ActionBar.TitleTextStyle&quot; parent=&quot;@android:style/TextAppearance.Holo.Widget.ActionBar.Title&quot;&gt;
    &lt;item name=&quot;android:textColor&quot;&gt;@color/titleColor&lt;/item&gt;
&lt;/style&gt;

答案1

得分: 9

使用主题中的ActionBar,您可以使用以下代码:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <item name="actionBarTheme">@style/ThemeOverlay.Actionbar</item>
</style>

<style name="ThemeOverlay.Actionbar" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar">
    <item name="android:textColorPrimary">@color/....</item>
</style>

如何使用Material Design更改操作栏文本颜色?

英文:

Using the ActionBar in your theme you can use:

 &lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.MaterialComponents.Light.DarkActionBar&quot;&gt;
        &lt;item name=&quot;actionBarTheme&quot;&gt;@style/ThemeOverlay.Actionbar&lt;/item&gt;
 &lt;/style&gt;

 &lt;style name=&quot;ThemeOverlay.Actionbar&quot; parent=&quot;ThemeOverlay.MaterialComponents.Dark.ActionBar&quot; &gt;
        &lt;item name=&quot;android:textColorPrimary&quot;&gt;@color/....&lt;/item&gt;
 &lt;/style&gt;

如何使用Material Design更改操作栏文本颜色?

huangapple
  • 本文由 发表于 2020年8月13日 21:46:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63396607.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定