Android ActionBar usage
Android ActionBar usage
Package com. example. actionbardemo2; import android. r. drawable; import android. app. activity; import android. app. actionBar; import android. app. fragment; import android. app. fragmentTransaction; import android. app. actionBar. tab; import android. graphics. color; import android. graphics. drawable. colorDrawable; import android. graphics. drawable. drawable; import android. OS. bundle; import android. view. layoutInflater; import android. view. menu; import android. view. menuItem; import android. view. view; import android. view. viewGroup; import android. OS. build; public class MainActivity extends Activity implements ActionBar. tabListener {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); ActionBar actionBar = getActionBar (); actionBar. setNavigationMode (ActionBar. NAVIGATION_MODE_TABS); Drawable draw = new ColorDrawable (Color. GREEN); actionBar. setBackgroundDrawable (draw); ActionBar. tab tab = actionBar. newTab (); tab. setText ("core products"); tab. setIcon (draw); tab. setTabListener (this); actionBar. addTab; tab = actionBar. newTab (); tab. setText ("platform product"); tab. setIcon (draw); tab. setTabListener (this); actionBar. addTab; // remove the icon on the right of the Small arrow on the left: // an actionBar on the left. setDisplayHomeAsUpEnabled (true); // indicates that LogoactionBar is disabled. setDisplayUseLogoEnabled (false); // use a transparent color to replace the original icon, which is equivalent to not displaying the actionBar. setIcon (new ColorDrawable (Color. TRANSPARENT) ;}@ Overridepublic void onTabReselected (Tab tab, FragmentTransaction arg1) {// TODO Auto-generated method stubCharSequence text = tab. getText (); if (text. equals ("core products") {} else if (text. equals ("platform product") {}}@ Overridepublic void onTabSelected (Tab arg0, FragmentTransaction arg1) {// TODO Auto-generated method stub} @ Overridepublic void onTabUnselected (Tab arg0, fragmentTransaction arg1) {// TODO Auto-generated method stub} @ Overridepublic 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 ;}}