Skip to content Skip to sidebar Skip to footer

Appcompat Actionbar Styling

I'm currently trying to use AppCompat instead of ActionbarSherlock. On Android 4+ devices I don't run into any problems, as the normal Actionbar and Holo theme are used. On lower

Solution 1:

You have to create your own style with the image you want to put on background. In your style.xml, you should create something similar to this:

values/styles.xml

<stylename="Theme.MyAppTheme"parent="@style/Theme.AppCompat.Light"><itemname="actionBarStyle">@style/ActionBarTabStyle.MyAppTheme</item></style><stylename="ActionBar.Solid.MyAppTheme"parent="@style/Widget.AppCompat.Light.ActionBar.Solid"><itemname="background">@drawable/your_background_image</item></style>

values-v14/styles.xml

<stylename="Theme.MyAppTheme"parent="@style/Theme.AppCompat.Light"><itemname="android:actionBarStyle">@style/ActionBarTabStyle.MyAppTheme</item></style><stylename="ActionBar.Solid.MyAppTheme"parent="@style/Widget.AppCompat.Light.ActionBar.Solid"><itemname="android:background">@drawable/your_background_image</item></style>

and you can use this 9-patch image :

9-patch image

Solution 2:

I use this code:

<resources><stylename="AppTheme"parent="Theme.AppCompat.Light"><itemname="actionBarStyle">@style/ActionBarTheme</item></style><stylename="ActionBarTheme"parent="@style/Widget.AppCompat.Light.ActionBar.Solid"><itemname="background">@color/red_action_bar</item></style></resources>

I hope this code is of great help.

Solution 3:

You have to override the theme of the action bar

Solution 4:

To show custom icon & color in AppCompatActivity we can paste this code:

values/styles.xml

<resources><stylename="Theme.MyAppTheme"parent="@style/Theme.AppCompat"><itemname="actionBarStyle">@style/ActionBar.Solid.MyAppTheme</item><itemname="icon">@drawable/ic_launcher</item></style><stylename="ActionBar.Solid.MyAppTheme"parent="@style/Widget.AppCompat.Light.ActionBar.Solid"><itemname="background">@color/white</item></style>

values-v14/styles.xml

<resources><stylename="Theme.MyAppTheme"parent="@style/Theme.AppCompat.Light"><itemname="android:actionBarStyle">@style/ActionBar.Solid.MyAppTheme</item><itemname="icon">@drawable/ic_launcher</item></style><stylename="ActionBar.Solid.MyAppTheme"parent="@style/Widget.AppCompat.Light.ActionBar.Solid"><itemname="android:background">@color/app_titile_bar_color</item></style>

You can use your custom background picture as well from @drawable/your_pic.png

To show app icon & Text you also paste this to your activity.

// set action Bar icon & TextActionBarmActionBar= getSupportActionBar();
    mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
            | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);

Post a Comment for "Appcompat Actionbar Styling"