0
votes

I am new in Android! I used Android Action Bar Style Generator to customize the theme of action bar, my style name is payam and Style compatibility was Appcompat.

I copy and paste the generated res files in my project folder and change Manifest record to /android:theme="@style/Theme.Payam"/

In my project, I have a class that extends ActionBarActivity (DetailText Activity),But after running my app nothing changes and the color of action bar does not change!

In Android Action Bar Style Generator,If I choose Style compatibility to Holo, when I run my project this Activity crashes The eclips says that you need to use Theme.Appcompat with this activity!

I don't understand why this happens! In styles_payam file there are multiple style records(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>

I chose the name of first style name (Theme.Payam) in Manifest theme,Is that true?

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

Any Idea welcome!

1
Did you also copy over all of the resources that the tool generated for you?Bryan Herbst
Yes, I coped generated res folder to my project directory.Mr Jan

1 Answers

1
votes

Since you are using AppCompat, you need to add these two lines inside you main theme (Theme.Payam). colorPrimary stands for ActionBar color and colorPrimaryDark stands for the color of Status Bar over the ActionBar. Meanwhile add values for firstcolor and secondcolor in colors.xml

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

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

</style>