3 Ways to hide the top status bar and title bar in Android _android

Source: Internet
Author: User
Tags stub

This article contains 3 kinds of hidden top status bar and title bar and a hidden Android 4.0 flat bottom status bar method, share for everyone to refer to, specific content as follows

Method One

public class Mainactivity extends activity
{

 @Override
 protected void onCreate (Bundle savedinstancestate)
 {
 super.oncreate (savedinstancestate);

 Hide title bar
 requestwindowfeature (window.feature_no_title);
 Hides the status bar
 GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
  WindowManager.LayoutParams.FLAG_FULLSCREEN);

 Setcontentview (R.layout.activity_main);
 }



Method Two

<!--hide both the status bar and the title bar-->
<activity
  android:name= "com.ysj.demo.MainActivity
  android:theme=" @ Android:style/theme.notitlebar.fullscreen "
  android:label=" @string/app_name ">
  <intent-filter>
    <action android:name= "Android.intent.action.MAIN"/>


    <category android:name= " Android.intent.category.LAUNCHER "/>
  </intent-filter>
</activity>

Method Three

<!--application theme. -->
<style name= "Apptheme" parent= "Appbasetheme" >
  <!--All customizations this are not specific To a particular api-level can go. -->
  <!--hide status bar-->
  <item name= "Android:windowfullscreen" >true</item>
  <!-- Hide title bar-->
  <item name= "Android:windownotitle" >true</item>
</style>

Note:

1, method One of the two pieces of code before Setcontentview ().

2, method Two can only hide both the status bar and the title bar.

3, method One and method two are only applied to single activity. Method three applies to the whole program.

For tablets running more than 4.0 Android systems, the above three methods do not hide the status bar below the screen, and should be handled as follows.

public class Startupactivity extends activity {@Override protected void onCreate (Bundle savedinstancestate) {Super
 . OnCreate (Savedinstancestate);
 
 Setcontentview (R.layout.activity_startup); 
     * * Hide the status bar at the bottom of the screen of the tablet running Android 4.0 +/try {String procid = "79"; if (Android.os.Build.VERSION.SDK_INT >= Android.os.Build.VERSION_CODES. Ice_cream_sandwich) ProcID = "42";  ICS//requires root permission Process proc = Runtime.getruntime (). EXEC (new string[] {"Su", "-C", "service call activity "+ ProcID +" S16 Com.android.systemui "}); 
   was Proc.waitfor ();  
   The catch (Exception ex) {Toast.maketext (Getapplicationcontext (), Ex.getmessage (), Toast.length_long). Show (); } @Override protected void OnDestroy () {//TODO auto-generated Method Stub * * Restore the Flat Panel screen running Android more than 4.0 system The status bar at the bottom of the screen/try {Process proc = runtime.getruntime (). EXEC (new string[] {"AM", "StartService", "-N", "Com.and roid.systemui/. Systemuiservice "}); 
     Proc.waitfor (); 
   catch (Exception e) {e.printstacktrace ();
 } Super.ondestroy ();  @Override public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds the items to the action Bar if
 It is present.
 Getmenuinflater (). Inflate (R.menu.startup, menu);
 return true; @Override public boolean onoptionsitemselected (MenuItem Item) {//TODO auto-generated the method stub switch (item.ge
  Titemid ()) {case r.id.action_exit:finish ();
 Break
 return true;

 }

}

Because there is no status bar, you must provide a way to exit the program in your program.

I hope this article will help you learn about Android software programming.

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.