设置自定义样式和操作栏

时间:2013-08-05 08:45:44

标签: android android-actionbar android-styles

我正在开发一个需要使用操作栏和标签栏的应用程序,我的第一个问题是为标签栏上的标签设置自定义文本样式,现在我想使用操作栏,但我自定义样式和操作栏有问题。我做了一个自定义样式:

styles.xml

<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. -->
    </style>

    <style name="CustomTheme" parent="@android:style/Theme">
        <item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
    </style>

    <style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
        <item name="android:textAppearance">@style/CustomTabWidgetText</item>
    </style>

    <style name="CustomTabWidgetText" parent="@android:style/TextAppearance.Widget.TabWidget">
        <item name="android:textSize">10sp</item>
        <item name="android:textStyle">bold</item>
    </style>

</resources>

现在我读了here我可以为自定义样式添加操作栏,所以我尝试这样做:

styles.xml

<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. -->
    </style>

    <style name="CustomTheme" parent="@android:style/Theme">
        <item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
        <item name="android:actionBarStyle">@style/Widget.ActionBar</item>
    </style>

    <style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
        <item name="android:textAppearance">@style/CustomTabWidgetText</item>
    </style>

    <style name="CustomTabWidgetText" parent="@android:style/TextAppearance.Widget.TabWidget">
        <item name="android:textSize">10sp</item>
        <item name="android:textStyle">bold</item>
    </style>

<style name="Widget.ActionBar" parent="android:Widget.Holo.Light.ActionBar">
    <item name="android:displayOptions">showHome|useLogo|showCustom</item>
    <item name="android:customNavigationLayout">@layout/custom</item>
</style>

</resources>

如果查看我的xml代码,您可以看到我添加Widget.ActionBar样式以在我的活动上显示操作栏。当我尝试运行我的应用程序时,我可以看到标签主机的自定义样式,但我看不到操作栏。 我需要操作栏来放置共享按钮。 你能救我吗?

1 个答案:

答案 0 :(得分:1)

您试试this吗?

这里给出了actionbarserlock。