如何锁定横屏或竖屏

一、在AndroidManifest.xml里声明Activity(每个)的时候加上一个属性:

android:screenOrientation,属性取值landscape为固定横屏、portrait为固定纵屏幕、unspecified为未指明方向。

二、代码设置横屏竖屏

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);// 横屏 
    //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //竖屏 
    setContentView(R.layout.main); 
} 

另:
//去标题
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
//全屏
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

//屏幕常亮
view.setKeepScreenOn(true)

你可能感兴趣的:(ANDROID)