修改ActionBar中Android项目的样式

发布于 2024-12-18 20:44:15 字数 1396 浏览 1 评论 0原文

如何修改 Android 应用程序操作栏上项目的样式?

我尝试了以下操作:

<item name="android:actionBarStyle">@style/ActionBar.Light</item>

<style name="ActionBar.Light" parent="@style/ActionBar">
        <item name="android:background">@color/black</item>
        <item name="android:actionMenuTextColor">#FF00FF</item>
</style>

我可以修改操作栏的背景,但不能修改操作栏中项目的文本颜色。我该怎么做呢?

编辑:

我尝试了几乎所有找到的 android:action 属性,但除了背景之外我无法更改任何内容。只有以下代码的第一个 ​​#FF0000 对我的代码进行了更改。无论我在测试样式上设置哪个值,它都不会改变任何东西。为什么会发生这种情况?

<item name="android:actionBarStyle">@style/ActionBar.Light</item>

<style name="ActionBar.Light" parent="@style/ActionBar">
        <item name="android:background">#FF0000</item>
        <item name="android:actionMenuTextColor">@style/Test</item>
        <item name="android:actionButtonStyle">@style/Test</item>
        <item name="android:actionModeBackground">@style/Test</item>
        <item name="android:actionMenuTextAppearance">@style/Test</item>
    </style>

    <style name="Test">
        <item name="android:textColor">@color/white</item>
        <item name="android:background">#FF0000</item>
    </style>

How can I modify the style of the items on the Action bar of an Android Application?

I tryed the following:

<item name="android:actionBarStyle">@style/ActionBar.Light</item>

<style name="ActionBar.Light" parent="@style/ActionBar">
        <item name="android:background">@color/black</item>
        <item name="android:actionMenuTextColor">#FF00FF</item>
</style>

The background of the Action bar I was able to modify, but not the text Colors of the items in the Action bar. How can I do it?

EDIT:

I tried pretty much all the android:action attributes I found, but I couldn't manage to change anything other than the background. Only the first <item name="android:background">#FF0000</item> of the following code makes changes on my code. No matter which values I put on the Test style, it doesn't change anything. Why is it happening?

<item name="android:actionBarStyle">@style/ActionBar.Light</item>

<style name="ActionBar.Light" parent="@style/ActionBar">
        <item name="android:background">#FF0000</item>
        <item name="android:actionMenuTextColor">@style/Test</item>
        <item name="android:actionButtonStyle">@style/Test</item>
        <item name="android:actionModeBackground">@style/Test</item>
        <item name="android:actionMenuTextAppearance">@style/Test</item>
    </style>

    <style name="Test">
        <item name="android:textColor">@color/white</item>
        <item name="android:background">#FF0000</item>
    </style>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丶视觉 2024-12-25 20:44:15

如果您想更改操作栏中菜单项的颜色,您必须在主题样式中设置 actionMenuTextColor。

<style name="PortfolioTheme" parent="android:style/Theme.Holo.Light">
   <item name="android:actionMenuTextColor">#24598a</item>
   <item name="actionMenuTextColor">#24598a</item>
</style>

您没有在 actionMenuTextAppearance 中定义菜单项颜色!

If you want to change the color of the menu items in the action bar you have to set the actionMenuTextColor in your theme style.

<style name="PortfolioTheme" parent="android:style/Theme.Holo.Light">
   <item name="android:actionMenuTextColor">#24598a</item>
   <item name="actionMenuTextColor">#24598a</item>
</style>

You don't define the menu item colors in the actionMenuTextAppearance!

行雁书 2024-12-25 20:44:15

您可以通过以下方式更改颜色:-

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

<style name="MyTheme.ActionBarStyle" parent="android:style/Widget.Holo.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/red</item>
</style>
</resources>

You can change the color by:-

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

<style name="MyTheme.ActionBarStyle" parent="android:style/Widget.Holo.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/red</item>
</style>
</resources>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文