Last active
August 29, 2015 13:57
-
-
Save linggom/9762847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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? :)