Вопрос

I'm developing an App for Android 3.0+ and I want to personalize the action bar by removing the title, which I can accomplish, my problem is that I also lose the background on the action bar, I would just like to remove the title and keep the remaining style. Here's what I'm currently using:

    <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>

I'd prefer not to change the Activity code to accomplish this.

Это было полезно?

Решение

Which theme are you using? That is probably defined in values-v11 or values-v14. If Theme.Holo.Light you have to change the actionBarStyle's parent style to Widget.Holo.Light.ActionBar.Solid.

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

Другие советы

Did you try this,

define this in your theme.xml file,

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

define this in your style.xml file,

<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>

Let me know if this works.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top