2

I'm new with android ... i want to have a simple activity with a bottom action Bar in all tutorials it's mentionned that there is a way with

android:uiOptions=”splitActionBarWhenNarrow”

but it does not work on tablet or smal device even when i added

 <meta-data android:name="android.support.UI_OPTIONS"
                android:value="splitActionBarWhenNarrow" />
        </activity>

this is my manifest.xml

 <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        >
        <activity
            android:name=".launchActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:uiOptions="splitActionBarWhenNarrow"
            android:name=".MainActivity"
           >
            <meta-data android:name="android.support.UI_OPTIONS"
                android:value="splitActionBarWhenNarrow" />
        </activity>
        <activity
            android:name=".DisplayMessageActivity"
            android:label="@string/title_activity_display_message" >
        </activity>


        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>

build file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "xxxxxxx"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
elpazio
  • 697
  • 2
  • 9
  • 25

2 Answers2

7

Android 5.0's default theme (Theme.Material) does not support the split action bar. Neither does the appcompat-v7 action bar backport anymore, though it used to.

Your options are either to switch to theme based off of Theme.Holo, put your own bar at the bottom of the screen (e.g., a Toolbar), or simply redesign your UI to avoid the split action bar.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • i changed apptheme like this but the app does not run anymore – elpazio Jun 11 '15 at 22:07
  • @elpazio: If by "does not run anymore", you mean that your app crashes, use LogCat to examine the Java stack trace: http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Jun 11 '15 at 22:11
  • java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. – elpazio Jun 11 '15 at 22:37
  • 1
    @elpazio: OK, you are attempting to use `appcompat-v7` as an action bar backport. I do not see that in your Gradle build file, but perhaps it's just not what is in the code listing in your question. Regardless, `appcompat-v7` requires `Theme.AppCompat` and does not support a split action bar at all. – CommonsWare Jun 11 '15 at 22:42
  • do you have any good tutorial to make a menu with a toolbar ? – elpazio Jun 12 '15 at 21:34
  • @elpazio: Not handy, sorry. – CommonsWare Jun 12 '15 at 21:36
2

I'm fully agree with @CommonsWare answer.

I just add a note.

If you build your app only for Lolipop(5.0) or higher(for now) the action bar may be represented by any Toolbar widget within the application layout. You can align components(also split them) inside since you are want.

Community
  • 1
  • 1
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119