Android锁定横屏、竖屏、去标题全屏

1.锁定横屏或竖屏。 

   在没有设置屏幕方向的情况下会默认设置为:android:screenOrientation="unspecified" 
   即未指明屏幕方向,会根据屏幕的方向做改变。 
a)在AndroidManifest.xml中配置: 
如果使某个Activity做横竖屏的变化,在Activity的标签中加入如下配置。 
<!-- android:screenOrientation="portrait" 竖屏 
android:screenOrientation="landscape " 横屏 
android:screenOrientation="unspecified" 未指明方向 
--> 
<activity 
            android:label="@string/app_name" 
            android:name=".LockTheScreenActivity" 
            android:screenOrientation="portrait" 
  ></activity> 

b)代码实现如下: 
@Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);// 横屏 
 //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) 竖屏 
        setContentView(R.layout.main); 
    } 


2.去标题

    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

  }

3.全屏

    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 

 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

  }


你可能感兴趣的:(Android锁定横屏、竖屏、去标题全屏)