Android Activity Common function settings (fullscreen, Portrait screen, etc.)

Source: Internet
Author: User

Activity fullscreen 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 the status bar

Note: The two-piece code that sets the full screen must precede Setcontentview (r.layout.main), or it will get 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);

Settings page default to vertical screen
Setrequestedorientation (activityinfo.screen_orientation_portrait);

Get the horizontal screen direction

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

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

The activity screen is always displayed

1:androidmanifest.xml Adding permissions

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

2: Code implementation

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

Android Activity Common function settings (fullscreen, Portrait screen, etc.)

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.