Prohibit Android horizontal screen vertical screen switch

Source: Internet
Author: User

In Android to let a program's interface always keep a direction, do not follow the direction of the phone to change the way: As long as the androidmanifest.xml inside the configuration of a bit can be.

Add the android:screenorientation= "Landscape" attribute to the Androidmanifest.xml activity (activity to disable diversion) (Landscape is landscape, Portrait is portrait).

In addition, the activity is restarted every time the screen orientation is switched on Android, so you should save the current active state before the activity is destroyed and load the configuration when the activity is re-create. To avoid restarting the activity when you turn the screen, you can redefine the direction in the Androidmanifest.xml file by adding android:configchanges= to each activity keyboardhidden| Orientation "property), and is controlled according to the activity's override onconfigurationchanged (Configuration Newconfig) method, which does not restart the activity at the time of the screen, but instead calls Onconfigurationchanged (Configuration newconfig) This method.

The sample code is as follows:

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.liananse.ideal"Android:versioncode= "1"Android:versionname= "1.1" >     <USES-SDKandroid:minsdkversion= "Ten" />     <ApplicationAndroid:icon= "@drawable/ic_launcher"Android:label= "@string/app_name" >        <ActivityAndroid:label= "@string/app_name"Android:name= "Com.liananse.WelcomeActivity"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation">            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                 <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>        <ActivityAndroid:name= "Com.liananse.activity.MainActivity"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation"></Activity>        <ActivityAndroid:name= "Com.liananse.activity.MusicActivity"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation"></Activity>        <ActivityAndroid:name= "Com.liananse.activity.config.IdealAbout"Android:theme= "@android: Style/theme.notitlebar"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation"></Activity>        <ActivityAndroid:name= "Com.liananse.activity.config.IdealSetting"Android:theme= "@android: Style/theme.notitlebar"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation"></Activity>        <ActivityAndroid:name= "Net.youmi.android.AdActivity"android:configchanges= "Keyboard|keyboardhidden|orientation"android:screenorientation= "Portrait"/>        <Meta-dataAndroid:name= "Youmi_channel"Android:value= "0" />    </Application>    <uses-permissionAndroid:name= "Android.permission.INTERNET"/>    <uses-permissionAndroid:name= "Android.permission.READ_PHONE_STATE"/>    <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE"/>    <uses-permissionAndroid:name= "Android.permission.ACCESS_COARSE_LOCATION"/>    <uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/></Manifest>

Prohibit Android horizontal screen vertical screen switch

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.