Android Activity common function settings (full screen, horizontal screen, etc.)

Source: Internet
Author: User

Activity full-screen Settings

Way 1:androidmanifest.xml

<activity android:name= "myacitivty" Android:theme= "@android: Style/theme.notitlebar.fullscreen"/>

Mode 2: Code implementation

Requestwindowfeature (Window.feature_no_title); Hide title bar

GetWindow (). SetFlags (Windowmanager.layoutparams.flag_fullscreen,windowmanager.layoutparams.flag_fullscreen); Hide Status bar

Note: The two pieces of code that set the full screen must be before Setcontentview (R.layout.main), or it will be an error.

Activity screen Settings

Way 1:androidmanifest.xml

<activity android:name= "myacitivty" android:screenorientation= "Landscape"/>/or "portrait"

Mode 2: Code implementation

Setrequestedorientation (Activityinfo.screen_orientation_landscape);

Get horizontal screen direction

int orientation = This.getresources (). GetConfiguration (). Orientation;

Common values for orientation can be activityinfo.screen_orientation_landscape (horizontal) or activityinfo.screen_orientation_portrait (vertical screen)

The Activity screen always shows

1:androidmanifest.xml Add Permissions

<uses-permission android:name= "Android.permission.WAKE_LOCK"/>

2: Code implementation

GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

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.