Activity sets full screen and Android to get screen width and height

Source: Internet
Author: User

The full screen setting in the Android program includes two parts: window full screen and A ctivity full screen.

Window full screen is the title bar used to hide time, power, signal, and other information at the top of the system. A cti full screen is the title bar of the hidden program. You can set it in the program code or modify the AndroidManifest. xml file.

1. modify the program code.

We need to add the corresponding code in the onCreate method of A ctivity. Pay attention to the location of the Code, which must be called before the setContentView () method.

Public class Home extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); // The title bar getWindow () of the program is not displayed (). setFlags (WindowManager. layoutParams. FLAG_FULLSCREEN, WindowManager. layoutParams. FLAG_FULLSCREEN); // The title bar setContentView (R. layout. main );}}

 

2. Modify AndroidManifest. xml.

You can modify the attribute values of tags or tags. The difference is that all the activities after the tag is modified will be in full screen mode, and the changes will only apply to the current Activity. Note: For android: theme = "@ android: style/Theme. NoTitleBar. Fullscreen", I have set them both. You can make adjustments based on your actual situation.

<? Xml version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: android = "http://schemas.android.com/apk/res/android" package = "org. dw. enotes "android: versionCode =" 1 "android: versionName =" 1.0 "> <application android: icon =" @ drawable/icon "android: label = "@ string/app_name" <! -- Here --> android: theme = "@ android: style/Theme. noTitleBar. fullscreen "> <activity android: name = ". activity. hello "android: label =" @ string/app_name "<! -- Here --> android: theme = "@ android: style/Theme. noTitleBar. fullscreen "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity> </application> <uses-sdk android: minSdkVersion =" 4 "/> </manifest>


 

Android gets the width and height of the screen. You only need to call the following code in the Activity:

Int screenWidth; // screen width int screenHeight; // screen height WindowManager windowManager = getWindowManager (); Display display = windowManager. getdefadisplay display (); screenWidth = display. getWidth (); screenHeight = display. getHeight ();
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.