Swarm App Android - Actionbar
Asked Answered
O

1

6

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

Overactive answered 7/9, 2014 at 22:0 Comment(3)
Use uiautomatorviewer and find out.Christenechristening
Thanks, that tool made its job.Overactive
@AlockLeo, if my answer helps, remember to accept.Menispermaceous
M
5

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];
    }
}
Menispermaceous answered 8/9, 2014 at 21:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.