Android actionbar title and gradient backgrounds

Source: Internet
Author: User

Need to be set in Androidmanifest.xml

Android:theme= "@style/theme.appcompat"

If the hint cannot be found, press settings:

As for how to introduce the method, please look at the previous article.

One. Use a picture as a background

Simply reference the picture in your code

 Public classMainactivity extends Actionbaractivity {PrivateActionBar ActionBar; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);                Setcontentview (R.layout.activity_main); ActionBar=Getsupportactionbar (); //Set TitleActionbar.settitle ("Bar Example"); Actionbar.setsubtitle ("work hard! "); //enable the user to click on the Actionbar icon and return to the previous activityActionbar.setdisplayhomeasupenabled (true) ; //Background ImageResources res =getresources (); drawable mydrawable=res.getdrawable (R.drawable.top_theme_blue);    Actionbar.setbackgrounddrawable (mydrawable); }

Two. Use gradient colors as backgrounds

2.1 Generating Actionbar_gradient_bg.xml files

<?xml version="1.0"encoding="Utf-8"? ><shape xmlns:android="http://schemas.android.com/apk/res/android"Android:shape="Rectangle"> <!--Android:startcolor and Android:endcolor, respectively, start and end colors Android:angle are gradient angles and must be multiples of 45. Linear gradient: Android:type="Linear"Radial gradient: Android:type="Radial"radial gradients need to specify radii such as: Android:gradientradius=" -"-<Gradient Android:angle=" the"Android:endcolor="#ff8c00"Android:startcolor="#FFFFFF"Android:type="Linear"/> </shape>

2.2 Specifying in code

Sets the gradient background        actionbar.setbackgrounddrawable (Getresources (). getdrawable (R.DRAWABLE.ACTIONBAR_GRADIENT_BG)

Android actionbar title and gradient backgrounds

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.