Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. package samples.exoguru.materialtabs;
  2.  
  3. import android.support.v4.view.ViewPager;
  4. import android.support.v7.app.ActionBarActivity;
  5. import android.os.Bundle;
  6. import android.support.v7.widget.Toolbar;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9.  
  10. /**
  11. * Created by Edwin on 15/02/2015.
  12. */
  13. public class MainActivity extends ActionBarActivity {
  14.  
  15. // Declaring Your View and Variables
  16.  
  17. Toolbar toolbar;
  18. ViewPager pager;
  19. ViewPagerAdapter adapter;
  20. SlidingTabLayout tabs;
  21. CharSequence Titles[]={"Home","Events"};
  22. int Numboftabs =2;
  23.  
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.activity_main);
  28.  
  29.  
  30. // Creating The Toolbar and setting it as the Toolbar for the activity
  31.  
  32. toolbar = (Toolbar) findViewById(R.id.tool_bar);
  33. setSupportActionBar(toolbar);
  34.  
  35.  
  36. // Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
  37. adapter = new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);
  38.  
  39. // Assigning ViewPager View and setting the adapter
  40. pager = (ViewPager) findViewById(R.id.pager);
  41. pager.setAdapter(adapter);
  42.  
  43. // Assiging the Sliding Tab Layout View
  44. tabs = (SlidingTabLayout) findViewById(R.id.tabs);
  45. tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
  46.  
  47. // Setting Custom Color for the Scroll bar indicator of the Tab View
  48. tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
  49. @Override
  50. public int getIndicatorColor(int position) {
  51. return getResources().getColor(R.color.tabsScrollColor);
  52. }
  53. });
  54.  
  55. // Setting the ViewPager For the SlidingTabsLayout
  56. tabs.setViewPager(pager);
  57.  
  58.  
  59.  
  60. }
  61.  
  62.  
  63. @Override
  64. public boolean onCreateOptionsMenu(Menu menu) {
  65. // Inflate the menu; this adds items to the action bar if it is present.
  66. getMenuInflater().inflate(R.menu.menu_main, menu);
  67. return true;
  68. }
  69.  
  70. @Override
  71. public boolean onOptionsItemSelected(MenuItem item) {
  72. // Handle action bar item clicks here. The action bar will
  73. // automatically handle clicks on the Home/Up button, so long
  74. // as you specify a parent activity in AndroidManifest.xml.
  75. int id = item.getItemId();
  76.  
  77. //noinspection SimplifiableIfStatement
  78. if (id == R.id.action_settings) {
  79. return true;
  80. }
  81.  
  82. return super.onOptionsItemSelected(item);
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement