Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style for android:uiOptions="splitActionBarWhenNarrow"?

Does anyone know the style resource to use for the split action bar when using sdk version 14 android:uiOptions="splitActionBarWhenNarrow" ?

For the normal ActionBar I can use

<item name="android:actionBarStyle">@style/MyActionBar</item>

But this does not automatically overflow to the split bar at the bottom.

I have tried

    <item name="android:actionBarSplitStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabBarStyle">@style/MyActionBar</item>

But they both have no effect on the Galaxy Nexus

like image 233
Heiko Rupp Avatar asked Apr 15 '12 07:04

Heiko Rupp


2 Answers

This question is old, but i've just handled the same problem. If it can help someone else...

The split bar is also styled using ActionBarStyle.

For example, if you want to style the bottom part of the split action bar, you can use the item named backgroundSplit in your MyActionBar style.

...
<item name="android:actionBarStyle">@style/MyActionBar</item>
...

<style name="MyActionBar">
    <item name="background">@drawable/action_bar_top_background</item>
    <item name="backgroundSplit">@drawable/action_bar_bottom_background</item>
</style>

you can use a style instead of the drawable to customize the backgrounds, but if prefer this to define backgrounds in drawables.

like image 40
niko34 Avatar answered Sep 18 '22 13:09

niko34


This answer is basically niko34's but in a little bit more detail. Currently I have both the top actionbar and the lower actionbar (the lower actionbar is more properly named as the split actionbar) styled the same, but you'll see it's pretty darn simple to style them differently. I am using ActionBarSherlock v4.2.0, and have tested and run this flawlessly on both a Samsung Galaxy S3 running Jelly Bean and an HTC Droid Incredible running Gingerbread.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="..."
    android:versionCode="1"
    android:versionName="0.1" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="16" />

    <application
        android:icon="@drawable/launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/main_activity_title"
            android:name=".MainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.Styled"
            android:uiOptions="splitActionBarWhenNarrow" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

res/values/themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
        <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
    </style>
    <style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
        <item name="background">@drawable/bg_actionbar</item>
        <item name="android:background">@drawable/bg_actionbar</item>
        <item name="backgroundSplit">@drawable/bg_actionbar</item>
        <item name="android:backgroundSplit">@drawable/bg_actionbar</item>
    </style>
</resources>

Here you can see how I'm referencing @drawable/bg_actionbar a couple of times. That is an xml file that is located in the res/drawable directory. Below is the source of that file.

res/drawable/bg_actionbar.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:src="@drawable/bg_tile"
    android:tileMode="repeat" />

Here, android:src="@drawable/bg_tile" is just referencing my bg_tile.png file, which is located in res/drawable-hdpi, res/drawable-ldpi, res/drawable-mdpi, and res/drawable-xhdpi.

So all of this was probably more information than necessary, but it's better than not having enough! :)

like image 144
Charles Madere Avatar answered Sep 21 '22 13:09

Charles Madere