更改操作栏主题时出错

时间:2015-06-18 15:38:18

标签: android android-actionbar

我是Android新手! 我使用Android Action Bar Style Generator来自定义操作栏的主题,我的样式名称是payam,样式兼容性是Appcompat。

我将生成的res文件复制并粘贴到我的项目文件夹中,并将Manifest记录更改为/ android:theme =" @ style / Theme.Payam" /

在我的项目中,我有一个扩展ActionBarActivity(DetailText Activity)的类,但在运行我的应用程序后没有任何变化,动作栏的颜色也没有改变!

在Android操作栏样式生成器中,如果我选择样式兼容Holo,当我运行我的项目时,此活动崩溃eclips说你需要将Theme.Appcompat用于此活动!

我不明白为什么会这样!在styles_payam文件中有多个样式记录(ActionBar.Solid.Payam,ActionBar.Transparent.Payam,PopupMenu.Payam,...)!

<resources>

<style name="Theme.Payam" parent="@style/Theme.AppCompat.Light">
    <item name="actionBarItemBackground">@drawable/selectable_background_payam</item>
    <item name="popupMenuStyle">@style/PopupMenu.Payam</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.Payam</item>
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.Payam</item>
    <item name="actionDropDownStyle">@style/DropDownNav.Payam</item>
    <item name="actionBarStyle">@style/ActionBar.Solid.Payam</item>
    <item name="actionModeBackground">@drawable/cab_background_top_payam</item>
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_payam</item>
    <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Payam</item>


</style>

<style name="ActionBar.Solid.Payam" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
    <item name="background">@drawable/ab_solid_payam</item>
    <item name="backgroundStacked">@drawable/ab_stacked_solid_payam</item>
    <item name="backgroundSplit">@drawable/ab_bottom_solid_payam</item>
    <item name="progressBarStyle">@style/ProgressBar.Payam</item>
</style>

<style name="ActionBar.Transparent.Payam" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="background">@drawable/ab_transparent_payam</item>
    <item name="progressBarStyle">@style/ProgressBar.Payam</item>
</style>

<style name="PopupMenu.Payam" parent="@style/Widget.AppCompat.Light.PopupMenu"> 
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_payam</item> 
</style>

<style name="DropDownListView.Payam" parent="@style/Widget.AppCompat.Light.ListView.DropDown">
    <item name="android:listSelector">@drawable/selectable_background_payam</item>
</style>

<style name="ActionBarTabStyle.Payam" parent="@style/Widget.AppCompat.Light.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator_ab_payam</item>
</style>

<style name="DropDownNav.Payam" parent="@style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
    <item name="android:background">@drawable/spinner_background_ab_payam</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_payam</item>
    <item name="android:dropDownSelector">@drawable/selectable_background_payam</item>
</style>

<style name="ProgressBar.Payam" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
    <item name="android:progressDrawable">@drawable/progress_horizontal_payam</item>
</style>

<style name="ActionButton.CloseMode.Payam" parent="@style/Widget.AppCompat.Light.ActionButton.CloseMode">
    <item name="android:background">@drawable/btn_cab_done_payam</item>
</style>

<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Payam.Widget" parent="@style/Theme.AppCompat">
    <item name="popupMenuStyle">@style/PopupMenu.Payam</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.Payam</item>
</style>

我在Manifest主题中选择了第一个样式名称(Theme.Payam)的名称,这是真的吗?

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="22" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Payam"
    >
    <activity
        android:name=".SplashScreen"
        android:label="" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="" >
    </activity>
    <activity
        android:name=".ContentList"
        android:label="" >
    </activity>
    <activity
        android:name=".DetailText"
        android:label="" >
    </activity>
            <activity
        android:name=".FavDetail"
        android:label="" >
    </activity>
            <activity
        android:name=".FavList"
        android:label="" >
    </activity>
</application>

欢迎任何想法!

1 个答案:

答案 0 :(得分:1)

由于您使用的是AppCompat,因此需要在主题(Theme.Payam)中添加这两行。 colorPrimary代表ActionBar颜色,colorPrimaryDark代表ActionBar上状态栏的颜色。同时在colors.xml中添加firstcolor和secondcolor的值

<style name="Theme.Payam" parent="@style/Theme.AppCompat.Light">

    <item name="colorPrimary">@color/firstcolor</item>
    <item name="colorPrimaryDark">@color/secondcolor</item>

</style>