【问题标题】:android 3.0+ action bar keep background when stylingandroid 3.0+ 操作栏在造型时保持背景
【发布时间】:2013-05-25 13:20:02
【问题描述】:

我正在为 Android 3.0+ 开发一个应用程序,我想通过删除标题来个性化操作栏,我可以完成,我的问题是我也丢失了操作栏上的背景,我只想删除标题并保留剩余样式。这是我目前使用的:

    <resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:actionBarStyle">@style/ActionBarNoTitle</item>
    </style>

    <style name="ActionBarNoTitle" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:displayOptions">showHome|useLogo</item>
    </style>

    </resources>

我不希望更改 Activity 代码来完成此操作。

【问题讨论】:

    标签: android styles android-actionbar android-3.0-honeycomb titlebar


    【解决方案1】:

    您使用的是哪个主题?这可能在values-v11values-v14 中定义。如果Theme.Holo.Light,则必须将actionBarStyle 的父样式更改为Widget.Holo.Light.ActionBar.Solid

    <style name="ActionBarNoTitle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
        <item name="android:displayOptions">showHome|useLogo</item>
    </style>
    

    【讨论】:

    • 谢谢,它可以工作,但这需要 minSDK 14,如果可能的话,我更喜欢 11。
    • 对于v11,它是Widget.Holo.Light.ActionBar
    • 我会将此标记为正确答案,尽管问题是v11 不支持暗操作栏,我不知道,我的错在那里,考虑到只有 0.1%的设备运行 Honeycomb,我将 minsdk 更改为 14。谢谢您的时间。
    【解决方案2】:

    你试过了吗,

    在你的 theme.xml 文件中定义它,

    <style name="CustomActionBar" parent="android:style/Theme.Holo.Light">
            <item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
    </style>
    

    在你的 style.xml 文件中定义它,

    <style name="CustomActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
            <item name="android:titleTextStyle">@style/NoTitleText</item>
            <item name="android:subtitleTextStyle">@style/NoTitleText</item>
    </style>
    
    <style name="NoTitleText">
            <item name="android:textSize">0sp</item>
            <item name="android:textColor">#00000000</item>
    </style>
    

    让我知道这是否有效。

    【讨论】:

    • 它确实有效,我已经尝试过这个解决方案,但似乎有点脏,考虑到有一种更清洁的方法可以做到这一点。它还利用了 api 11 的主题。无论如何,谢谢:)
    猜你喜欢
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多