1

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 :) ..

Adly
  • 597
  • 3
  • 12
  • 23
  • "But a lot of errors appears." is there any error in using uiOptions="splitActionBarWhenNarrow" ? – Dheeresh Singh Jun 20 '12 at 13:15
  • NO not in that line, another for "WindowsTitleBackground" on the style.xml file! .. I read about splitactionbarwhenNarrow but I couldn't apply it because the errors :( – Adly Jun 20 '12 at 13:21
  • it says that WindowsTitleBackground is not a resource for android .. that's when I use GreenDroid Library ! .. – Adly Jun 20 '12 at 13:24

2 Answers2

3

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

RTB
  • 5,773
  • 7
  • 33
  • 50
  • java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{me.adly.action/me.adly.action.InflationDemo}: java.lang.ClassNotFoundException: me.adly.action.InflationDemo it gives me that error in the log cat tracer!? so what's the problem? – Adly Jun 20 '12 at 13:40
  • The InflationDemo activity was not found in your project. Check your manifest and activity names or you intent objects. – RTB Jun 20 '12 at 13:46
  • That's worked :), that's what appeared for me ! : http://postimage.org/image/tsyneui1j/ can you provide me with a link for the source code of the snippet above? – Adly Jun 20 '12 at 13:57
  • Here's the snippet link that i found from another user: http://stackoverflow.com/questions/8465258/how-can-i-force-the-action-bar-to-be-at-the-bottom-in-ics If my answer helped please accept it, thank you. – RTB Jun 20 '12 at 14:21
0

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.

StuStirling
  • 15,601
  • 23
  • 93
  • 150
  • I read about it at first, But I couldn't find any sample code to apply perfectly, can you help me on that? – Adly Jun 20 '12 at 13:22
  • I made it sucessfully, but there is a thing about what you said, when I add 5 elements in the menu, the action bar shows only 3 elements and doesn't make like the pic above ? so what do you think the problem? i put what you said about : splitactionbarwhennarow, but still not working ..??? – Adly Jun 20 '12 at 16:43