Advertisement
vergepuppeter

Custom ActionBar

Feb 2nd, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. public class MainActivity extends ActionBarActivity {
  2.  
  3. private FragmentTabHost mTabHost;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8.  
  9. getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  10. getSupportActionBar().setCustomView(R.layout.actionbar_custom); //Ni layout untuk actionbar
  11.  
  12. setContentView(R.layout.bottom_tabs);
  13.  
  14. mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
  15. mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
  16.  
  17. Bundle b = new Bundle();
  18. b.putString("key", "Home");
  19. mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator("Home",getResources().getDrawable(R.drawable.tab_one)),HomeFragment.class, b);
  20. mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#D6D5D6"));
  21. TextView tv1 = (TextView) mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title); //Unselected Tabs
  22. tv1.setTextColor(Color.parseColor("#000000"));
  23. }
  24.  
  25. @Override
  26. public boolean onCreateOptionsMenu(Menu menu) {
  27. // Inflate the menu; this adds items to the action bar if it is present.
  28. getMenuInflater().inflate(R.menu.main, menu);
  29. return true;
  30. }
  31.  
  32. public void setActionbarTitle(String title) //Panggil method ni kalau nak ubah apa2 kat actionbar, dlm kes ni ubah title
  33. {
  34. View v = getSupportActionBar().getCustomView();
  35. TextView titleTxtView = (TextView) v.findViewById(R.id.actionbar_title);
  36. titleTxtView.setText(title);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement