安卓自学,手机上的横竖屏切换,状态栏隐藏

手机切换横竖屏崩溃在mainfest.xml对应的ACTIVITY中 添加这段android:configChanges="orientation|screenSize" 就不会崩溃啦


动态设置横竖屏 方法 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE一面横屏

  ActivityInfo.SCREEN_ORIENTATION_PORTRAIT一面竖屏

  ActivityInfo.SCREEN_ORIENTATION_NOSENSOR    不受影响默认竖屏

  ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE  两面横屏转换

  ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT    两面竖屏转换

  ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR     根据重力变换四面

XML中设置横竖屏

android:screenOrientation="landscape" 

// 隐藏标题栏
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
// 隐藏手机状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

隐藏手机虚拟导航栏

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

沉浸模式 

来自郭大神博客 http://blog.csdn.net/guolin_blog/article/details/51763825


    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus && Build.VERSION.SDK_INT >= 19) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }

你可能感兴趣的:(android)