简体   繁体   中英

Android App How to rotation screen orientation temporarily

Is there any way to temporarily stop rotating the screen, perform a restore operation? Request can not be turned off gravity sensor, it only prohibits the rotating screen.

To disable the orientation change you need to tell Android that you want to handle it by yourself.

To do so, add the following to your activity in the mainfest.xml:

android:configChanges="orientation"

Now override the following in the Activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}

If you don't load a new layout here you will just keep the orientation.

Further details you can find here: http://developer.android.com/guide/topics/resources/runtime-changes.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM