Adly
Adly

Reputation: 597

implementing the action bar in the android

gmail app in android

I want to implement an action bar for my own android app like the one on the bottom on the picture. I searched a lot, But a lot of errors appears.

I tried some libraries for some help like : Greendroid and ActionBarSherlock but none of them work, Or I couldn't use them perfectly! ..

I'm really in need for that action bar in my app.

I will be grateful if someone could help me with some Samples or codes or explain it to me.

Thanks a lot :) ..

Upvotes: 1

Views: 4660

Answers (2)

StuStirling
StuStirling

Reputation: 16191

I think you need to look at something called SplitActionBar.

The documentation for this is here.

From reading briefly about it, it only applies to "Narrow" screens and you declare that you want to use the split action bar by adding uiOptions="splitActionBarWhenNarrow" into the or element in the AndroidManifest.xml file.

You may be able to force it to appear all the time but I don't know as I haven't used it before.

I hope this helps.

Upvotes: 0

RTB
RTB

Reputation: 5823

You can use a SplitActionBar. Your application suppost to be running on Android 4.0 (API level 14) or higher

the fix is to always have an item in the top bar that prevents the bottom content from ever fitting in there, thus forcing everything into the bottom bar. Look at this sample project from another user:

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

  <application android:hardwareAccelerated="true"
               android:icon="@drawable/cw"
               android:label="@string/app_name">
    <activity android:label="@string/app_name"
              android:name=".InflationDemo"
              android:uiOptions="splitActionBarWhenNarrow">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
  <uses-sdk android:minSdkVersion="4"
            android:targetSdkVersion="11" />
  <supports-screens android:anyDensity="true"
                    android:largeScreens="true"
                    android:normalScreens="true"
                    android:smallScreens="true"
                    android:xlargeScreens="true" />
</manifest>

He used this code for his activity:

private void setupActionBar() {
ActionBar actionBar = getActionBar();

ViewGroup v = (ViewGroup)LayoutInflater.from(this)
    .inflate(R.layout.conversation_list_actionbar, null);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
        ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(v,
        new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_VERTICAL | Gravity.RIGHT));

mUnreadConvCount = (TextView)v.findViewById(R.id.unread_conv_count);
}

http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar

Upvotes: 3

Related Questions