Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
Combine tab into actionbar,
i'm using pager sliding tab strinb (
package com.srin.flores;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import com.astuetz.Pagerslidingtabstrip;
public class MainActivity extends Activity {
private PagerSlidingTabStrip mTabs;
private MainPageAdapter mAdapter;
private ViewPager mPager;
private ActionBar mActionBar;
protected void onCreate(Bundle savedInstanceState) {
mActionBar = getActionBar();
mAdapter = new MainPageAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(;
LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//inflate the pagerslidingtab strip from a xml layout
//Put the pagerslidingtabstrip to Linearlayout
View v = inflator.inflate(R.layout.layout_tabs, null);
mTabs = (PagerSlidingTabStrip)v.findViewById(; //find the pagerslidingtabstrip from view
mTabs.setViewPager(mPager); //set the viewpager to view
mActionBar.setDisplayShowCustomEnabled(true); //don't forget this so we can set custom view to actionbar
mActionBar.setCustomView(v); //put the view to actionbar
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;

This comment has been minimized.

Copy link

@nitrico nitrico commented May 20, 2014

Hey! Thanks for the gist but I would like to see another files such as layouts or a screenshot to check the final result, is it possible? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment