Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swarm App Android - Actionbar

What is the element that is used for Swarm Android app's actionbar? I think it's neither the native android actionbar nor actionbarsherlock.

screenshot of swarms actionbar

like image 723
Alaattin KAYRAK Avatar asked Sep 07 '14 22:09

Alaattin KAYRAK


1 Answers

After using uiautomatorviewer, it can be seen that the base components were ImageButtons inside of a HorizontalScrollView for the left portion, and a LinearLayout with an ImageButton for the right portion. However, this doesn't detail how to attain the sliding animation or how to space out the two functioning parts well.

I managed to recreate it using this fantastic library and a little massaging of views. Basically, you feed the Pager Sliding Tab Strip(PSTS) to the actionbar as a custom view.

//I call this in the onCreate()of my activity
void setupActionBar() {

    ActionBar actionBar = getActionBar();

    View vwActionBar = View.inflate(this, R.layout.action_bar_main, null);
    tabs = (PagerSlidingTabStrip) vwActionBar.findViewById(R.id.tabs);
    actionBar.setCustomView(vwActionBar);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
}

With the action_bar_main.xml being this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="match_parent">


    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="wrap_content"
        android:layout_height="?android:attr/actionBarSize"
        android:layout_alignParentBottom="true"
        />


</RelativeLayout>

You also have to change how the FragmentPagerAdapter sets up the PSTS. The libraries samples hold a good example of how to do this, but here is mine.

public class MyPagerAdapter extends FragmentPagerAdapter
    implements PagerSlidingTabStrip.IconTabProvider {

    private final int[] ICONS = {
        R.drawable.ic_home,
        R.drawable.ic_dashboard,
        R.drawable.ic_insights,
        R.drawable.ic_stream
    };

    public MyPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public int getCount() {
        return ICONS.length;
    }

    @Override
    public android.support.v4.app.Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override public int getPageIconResId(int i) {
        return ICONS[i];
    }
}
like image 107
Michael Alan Huff Avatar answered Nov 03 '22 04:11

Michael Alan Huff