Skip to content Skip to sidebar Skip to footer

Action Bar Doesn't Accept Personal Styles

I am trying to personilize my action bar. I want it to support API-9 and above the problem is that action bar doesn't accept changed made in styles.xml and items are not shown. thi

Solution 1:

The official way to set the action bar color with appcompat-v7 is via colorPrimary on the activity theme:

<?xml version="1.0" encoding="utf-8"?><resources><stylename="Theme.Apptheme"parent="Theme.AppCompat"><itemname="colorPrimary">@color/primary</item><itemname="colorPrimaryDark">@color/primary_dark</item><itemname="colorAccent">@color/accent</item></style></resources>

With regards to the icon, this has been asked many, many times, and the answer (getSupportActionBar().setDisplayShowHomeEnabled(true); and getSupportActionBar().setIcon(R.drawable.ic_launcher);) can be found via Web searches for appcompat icon.

Solution 2:

Go for Custom theme , add themes.xml inside res-->values folder

use this code for custom actionbar

themes.xml

<?xml version="1.0" encoding="utf-8"?><resources><!-- the theme applied to the application or activity --><stylename="CustomActionBarTheme"parent="@style/Theme.AppCompat.Light.DarkActionBar"><itemname="android:actionBarStyle">@style/MyActionBar</item><itemname="android:actionBarTabStyle">@style/MyActionBarTabs</item><!-- Support library compatibility --><itemname="android:actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item><itemname="android:actionBarTabBarStyle">@style/Divider</item></style><!-- for Tab divider --><stylename="Divider"parent="@android:style/Widget.Holo.ActionBar.TabBar"><itemname="android:divider">@android:color/transparent</item> //or use your transparent drawable image
    <itemname="android:showDividers">middle</item><itemname="android:dividerPadding">0dp</item></style><!-- ActionBar styles --><stylename="MyActionBar"parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"><itemname="android:background">@color/easy</item><!-- Support library compatibility --><itemname="background">@color/easy</item></style><stylename="MyActionBarTabs"parent="@style/Widget.AppCompat.ActionBar.TabView"><itemname="android:background">@drawable/actionbar_tab_indicator</item></style><stylename="MyTheme.ActionBar.TabText"parent="android:style/Widget.Holo.ActionBar.TabText"><!-- This is a Black text color when selected and a WHITE color otherwise --><itemname="android:textColor">@color/selector_tab_text</item></style></resources>

manifest file call -->CustomActionBarTheme

<applicationandroid:allowBackup="true"android:icon="@drawable/easylogo"android:label="@string/app_name"android:largeHeap="true"android:theme="@style/CustomActionBarTheme" ><activityandroid:name="com.example.Start"android:label="@string/app_name"android:screenOrientation="portrait" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application>

Post a Comment for "Action Bar Doesn't Accept Personal Styles"