ActionBar (2) Title and gradient background settings

Source: Internet
Author: User
Android: theme@styleTheme.AppCompat needs to be set in AndroidManifest. xml if the prompt is not found, follow the settings: as to how to introduce the method, please refer to the previous article. I. PublicclassMainActivityextendsActionBarActivity {private

Android: theme = @ style/Theme. AppCompat needs to be set in AndroidManifest. xml. If you cannot find android: theme = @ style/Theme. AppCompat, follow the settings below: For how to introduce the method, see the previous article. I. Use the image as the background and directly reference the image in the Code. public class MainActivity extends ActionBarActivity {private

You need to set in AndroidManifest. xml

Android: theme = "@ style/Theme. AppCompat"

If you cannot find the prompt, follow the settings below:

For how to introduce the method, see the previous article.


I. Use an image as the background

Reference the image directly in the code.

Public class MainActivity extends ActionBarActivity {private ActionBar actionBar; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); actionBar = getSupportActionBar (); // you can specify the title actionBar. setTitle ("Bar example"); actionBar. setSubtitle ("effort! "); // The user clicks the ActionBar icon and returns the previous activity actionBar. setDisplayHomeAsUpEnabled (true );// Background image Resources res = getResources (); Drawable myDrawable = res. getDrawable (R. drawable. top_theme_blue); actionBar. setBackgroundDrawable (myDrawable );}



II. Use gradient color as the background

2.1 generate the actionbar_gradient_bg.xml File

 
         
         
       
 

2.2 specify in the code
// Set the gradient background actionBar. setBackgroundDrawable (getResources (). getDrawable (R. drawable. actionbar_gradient_bg ));

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.