加载在setContentView前面显示
requestWindowFeature(Window.FEATURE_NO_TITLE); //不显示Activity标题
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//保持全屏,不显示系统状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);//保持屏幕不变黑
需要对象
PowerManager.WakeLock wakeLock;
启用屏幕常亮功能
wakeLock = ((PowerManager)getSystemService(POWER_SERVICE)).
newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "MyActivity");
wakeLock.acquire();
关闭屏幕常亮功能
if (wakeLock != null) {
wakeLock.release();
}
需要权限
<uses-permission android:name="android.permission.WAKE_LOCK" />
为了不对其他程序造成影响,启用和关闭屏幕常亮的代码一般被放在 Activity 的 onResume() 和 onPause() 事件中
方法 2: use the window flag FLAG_KEEP_SCREEN_ON
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);// Set keep screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}