簡體   English   中英

設置自定義樣式和操作欄

[英]Set custom style and action bar

我正在開發一個需要與操作欄和標簽欄一起使用的應用程序,我的第一個問題是為標簽欄上的標簽設置自定義文本樣式,現在我想使用操作欄,但是自定義樣式和操作欄有麻煩。 我做了一個自定義樣式,所以:

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>

現在,我在這里閱讀可以將操作欄添加到自定義樣式的方法,因此我嘗試這樣做:

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樣式以在我的活動上顯示操作欄。 當我嘗試運行我的應用程序時,我可以看到選項卡宿主的自定義樣式,但是看不到操作欄。 我需要操作欄來放置共享按鈕。 你能幫助我嗎?

你試試這個

在這里給它做actionbarserlock。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM