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