Skip to content

Instantly share code, notes, and snippets.

@linggom
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linggom/9762847 to your computer and use it in GitHub Desktop.
Save linggom/9762847 to your computer and use it in GitHub Desktop.
/*
Combine tab into actionbar,
i'm using pager sliding tab strinb (https://github.com/astuetz/PagerSlidingTabStrip)
*/
package com.srin.flores;
import android.app.ActionBar;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import com.me.example.adapter.MainPageAdapter;
import com.astuetz.Pagerslidingtabstrip;
public class MainActivity extends Activity {
private PagerSlidingTabStrip mTabs;
private MainPageAdapter mAdapter;
private ViewPager mPager;
private ActionBar mActionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mActionBar = getActionBar();
mAdapter = new MainPageAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pagerContent);
mPager.setAdapter(mAdapter);
mPager.setOffscreenPageLimit(3);
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(R.id.tabs); //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
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
@nitrico
Copy link

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