简体   繁体   中英

Custom background for an ActionBar Item

I would like to set a custom background/drwable for my action bar item. Ideally to have the "Save job" thing as a "white text over dark blue" button.

Any hint ?

Basic editting of action bar items straight from: http://developer.android.com/training/basics/actionbar/adding-buttons.html

<!-- Settings, should always be in the overflow -->
<item android:id="@+id/SAVE_JOB"                     //Save job button
      android:textColorolor="Your hex color"         //Whatever color you want
      android:background="@drawable/yourbackground"  //Whatever picture you want
      android:showAsAction="always" />

The yourbackground will be located in your drawable folder, and your hex color will be in the fashion #FFFFFF .

    ActionBar actionBar = getSupportActionBar();

    View actionBarView = getLayoutInflater().inflate(
            R.layout.custom_bar, null);

    actionBar.setCustomView(actionBarView);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setDisplayShowCustomEnabled(true);

Set your custom actionbarview and do whatever you want in xml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM