Android ActionBar usage

Source: Internet
Author: User

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 ;}}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.