【问题标题】:Action bar custom style in my case在我的情况下操作栏自定义样式
【发布时间】:2012-03-02 13:18:34
【问题描述】:

我正在使用 Android 原生操作栏。我想添加我自己的可绘制资源作为操作栏的背景。所以,我做了一个如下的主题:

res/values/themes.xml:

<style name="Theme.MyStyle" parent="android:style/Theme.Holo.Light">
    <item name="android:background">@drawable/my_bg</item>
</style>

然后,在 AndroidManifest.xml 文件中,我将此样式添加到我的应用程序中:

<application
        android:debuggable="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"

        android:theme="@style/Theme.MyStyle"
        >
   <activity ...>
   <activity .../>
   ...

</application>

但是,背景可绘制对象不仅应用于操作栏应用于所有片段的内容。为什么?

我的第二个问题是,如何自定义 overflow 图标和操作栏上最左侧的“向上”按钮??

【问题讨论】:

    标签: android android-layout android-intent android-widget android-actionbar


    【解决方案1】:

    试试

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <!-- the theme applied to the application or activity -->
        <style name="Theme.MyStyle" parent="@android:style/Theme.Holo">
            <item name="android:actionBarStyle">@style/MyActionBar</item>
            <!-- other activity and action bar styles here -->
        </style>
    
        <!-- style for the action bar backgrounds -->
        <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
            <item name="android:background">@drawable/ab_background</item>
            <item name="android:backgroundStacked">@drawable/ab_background</item>
            <item name="android:backgroundSplit">@drawable/ab_split_background</item>
        </style>
    </resources>
    

    customize the logo 使用 setDisplayUseLogoEnabled(boolean)

    More info

    【讨论】:

    • 是的,我关注了那里的帖子,并产生了问题,我在这里问。我更喜欢对我的问题做出更具体的回答,而不是再次回到循环中。我制作自定义样式没有问题,问题是我在 AndroidManifest.xml 中将样式添加到我的应用程序中,但它适用于任何地方,而不仅仅是操作栏。
    • 我没有使用操作栏上的标签
    • 我认为您的问题出在属性样式父级上。尝试仅将其应用于"android:style/Widget.Holo.Light.ActionBar"
    • 尝试最后一次编辑,请在投反对票之前考虑时间和精力。谢谢
    • 您好,您的最后一次编辑正在运行。我明白了原因,我应该先将我的操作栏样式放入应用程序样式中,然后添加到我的应用程序中。谢谢!顺便问一下,应用到应用程序的样式是否必须使用“Theme.Holo”作为父样式?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多