Android _ set the title bar features

Source: Internet
Author: User

During development, full screen display, custom titles (using buttons and other controls), and other requirements are often required. This requires the most appropriate processing of the title bar.

A very important method is used: requestwindowfeature (INT featureid ).

The featureid value is as follows:

  1. Default_features: default system status, which is generally not required
  2. Feature_context_menu: Enable contextmenu. This option is enabled by default. Generally, you do not need to specify
  3. Feature_custom_title: Custom title. You must specify a custom title. For example, when the title is a button
  4. Feature_indeterminate_progress: uncertain progress (circled)
  5. Feature_left_icon: icon on the left of the title bar
  6. Feature_no_title: No title
  7. Feature_options_panel: enables the option panel function. It is enabled by default.
  8. Feature_progress: Progress indicator Function
  9. Feature_right_icon: icon on the right of the title bar

Next we will create a project called windowfeaturedemo to explain in detail:

Windowfeaturedemoactivity. Java

Package COM. tianjf; import android. app. activity; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. view. window; import android. view. windowmanager; // 1. default_features: default system status, which is generally not required. // 2. feature_context_menu: Enable contextmenu. This option is enabled by default. You do not need to specify/3. feature_custom_title: Custom title. You must specify a custom title. For example, when the title is a button, // 4. feature_indeterminate_progress: uncertain progress (circled) // 5. feature_left_icon: icon on the left of the title bar // 6. feature_no_title: No title // 7. feature_options_panel: enables the option panel function. It is enabled by default. // 8. feature_progress: Progress indicator // 9. feature_right_icon: public class windowfeaturedemoactivity extends activity {@ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // uncertain progress (circled) showfeature_indeterminate_progress (); // determined progress (progress bar) // showfeature_progress (); // icon on the left of the title bar // showfeature_left_icon (); // No title // showfeature_no_title ();}/*** uncertain progress (circled) */private void showfeature_indeterminate_progress () {// first request a window feature // note that this sentence must be added to setcontentview (R. layout. main); front, otherwise the error requestwindowfeature (window. feature_indeterminate_progress); setcontentview (R. layout. main); // set whether an ambiguous progress bar in the title bar can be displayed. If you need to indicate that the progress bar is being processed, set it to true, set it to false after processing. // note that this sentence is displayed only when it is added to the circle. // note that this sentence should be added to setcontentview (R. layout. <G id = "1"> main "); otherwise, the page cannot be displayed in the circle. setprogressbarindeterminatevisibility (true);}/*** determined progress (progress bar) */private void showfeature_progress () {// request the "Progress (progress bar)" feature requestwindowfeature (window. feature_progress); setcontentview (R. layout. main); // display the progress (progress bar) setprogressbarvisibility (true); // set the title to null, leaving only one progress bar settitle (""); getwindow (). setfeatureint (window. feature_progress, window. progress_visibility_on); // change the value of progressbar through a thread. New thread (New runnable () {public void run () {for (INT I = 0; I <10; I ++) {try {thread. sleep (1000); message m = new message (); M. what = (I + 1) * 20; windowfeaturedemoactivity. this. mymessagehandler. sendmessage (m);} catch (exception e) {e. printstacktrace ();}}}}). start ();}/*** icon on the left of the title bar */private void showfeature_left_icon () {requestwindowfeature (window. feature_left_icon); setcontentview (R. layout. main); getwindow (). setfeaturedrawableresource (window. feature_left_icon, R. drawable. ic_launcher);}/*** no title */private void showfeature_no_title () {requestwindowfeature (window. feature_no_title); setcontentview (R. layout. main); // if this sentence is set to full screen without adding, only titlegetwindow () is hidden (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen);}/*** thread */handler mymessagehandler = new handler () {@ overridepublic void handlemessage (Message MSG) {// set a progress bar value setprogress (100 * MSG. what); // set a progress bar value setsecondaryprogress (100 * MSG. what + 10); super. handlemessage (MSG );}};}

The explanations are all in the annotations.

Over!

Related Article

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.