Android Remove the status bar method Rollup _android

Source: Internet
Author: User

In real-world application development, we sometimes need to set the activity to a full screen display, in general, there are two ways to set the Full-screen display effect:

One, by being able to set in code,

Second, set the full screen through the manifest configuration file.

First: Before the code oncreate inside Setcontentview set (as follows)

View Plaincopy to Clipboardprint?
public void OnCreate (Bundle savedinstancestate) { 
super.oncreate (savedinstancestate); 
Cancellation of title 
requestwindowfeature (window.feature_no_title); 
Cancels the status bar
GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, 
WindowManager.LayoutParams.FLAG_FULLSCREEN); 
Setcontentview (R.layout.main); 
}

But note: Set in the code, set the untitled and set the full screen of two pieces of code to be placed in Setcontentview (R.layout.main) (interface rendering, complete and then full screen is not possible) before this code. Otherwise, it will be an error.

Second: Set up in the manifest configuration file

The first of these methods

① Create a Theme.xml file in the Res/values directory (used to put styles)

<?xml version= "1.0" encoding= "Utf-8"?> 
<!--name is the name of the style and parent inherits that parent class style--> 
<style name= "Theme_fullscreen" parent= "Android:Theme.Black" > 
<item name= "Android:windownotitle" >true</item> <!--set Untitled--> 
<item name= "Android:windowfullscreen" >?android:windownotitle </item> <!--whether to fill the slow screen, reference android:windownotitle value? android:windownotitle, depending on the value of Android:windownotitle-->
</style> 
</resources>

②<activity android:name= ". Login. Loginactivity "Android:theme=" @style/theme_fullscreen "/>

The second method

<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= 
"http://schemas.android.com/apk/res/" Android " 
package=" Com.andyidea " 
android:versioncode=" 1 " 
android:versionname=" 1.0 "> 
< USES-SDK android:minsdkversion= "8"/> 
<application android:icon= "@drawable/icon" android:label= "@string App_name "> 
<activity android:name=". Login. Loginactivity " 
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 > 
</application> 

Only go to the program title bar to set the entire application no title

Third: This is not commonly used in general applications, that is, under the Res/values directory to create a new Style.xml file for example:

<?xml version= "1.0" encoding= "UTF-8"?> <resources> <style name= "Theme_notitle" > <item name= " Android:windownotitle ">true</item> </style> </resources>

In this way, we customize a style, which is equivalent to a theme, and then define in the Androidmanifest.xml file

<application android:icon= "@drawable/icon" android:label= "@string/app_name" android:theme= "@style/theme_ Notitle ">

This can also achieve the effect of removing the title bar

The above has summed up three kinds of Android to remove the status bar method, I hope this article can help everyone.

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.