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

Source: Internet
Author: User

Activity fullscreen settings

Mode 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 Set

Mode 1: Androidmanifest.xml

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

Mode 2: code implementation

setrequestedorientation (activityinfo.screen_orientation_landscape);

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);

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.