Wednesday, February 20, 2019

Set activity fullscreen, keep screen always on

Normaly, when you run app, on top screen will see app name and icon.

To hide them, add this like above the line setContentView.
requestWindowFeature(Window.FEATURE_NO_TITLE);
App name and icon disappear, but still have the status bar.

To remove status bar, copy this line in to class declare in AndroidManifest.xml
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

This time, screen become black like this.

To solve this, we set background to activity with white color.
android:background="#ffffff"

Screen will be white as normal.
If you develop a reading book app, to keep screen always on, add this line below setContentView.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


No comments:

Post a Comment