Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ActionBar backbutton and tabs

I want to create an ActionBar and a tabbed navigation like the google+ app.

I used this example as a starting point and now I have a great actionbar:

  • http://developer.android.com/resources/samples/ActionBarCompat/index.html

I've also included a ViewPager and a TabHost to have tabs and scrolling left/right Fragments.

What i need is to show the back arrow in version prior to honeycomb. If I set getActionBar().setDisplayHomeAsUpEnabled(true), the arrow is automatically show in version >= honeycomb.

  • How can I do that in version prior to honey?

What I also want to have is Tabs like the google+ app.

This is how is my tab bar looks:

removed dead ImageShack link

...and this is what i want:

removed dead ImageShack link

I can't find any example to style tab bars like that one.

like image 217
Ste Avatar asked Dec 15 '11 10:12

Ste


2 Answers

I would recommend you the ActionBarSherlock for ActionBar compatibility with Android <3. It is a better implementation that the example offered in the developers page.

Using this package, the back arrow will appear when you add to your activity the following line.

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Regarding the Google+ tabs, I have found the widget ViewFlow very useful and looking exactly the same. Moreover, you don't have any backward compatibility issues. Have a look to the CircleFlowIndicator example.

like image 113
miguel.rodelas Avatar answered Oct 12 '22 20:10

miguel.rodelas


You can use ActionBarSherlock and a ViewPager with ViewPagerIndicator to achieve the desired look. These libraries also work pre ICS.

As miguel.rodelas suggested, use getSupportActionBar().setDisplayHomeAsUpEnabled(true) for the home arrow. In onOptionsItemSelected you can catch it by the id android.R.id.home.

like image 22
stoilkov Avatar answered Oct 12 '22 21:10

stoilkov