Trouver la mise en page de la racine de l'activité. par exemple, si la mise en page de racine est un LinearLayout
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xml);
LinearLayout root = (LinearLayout) findViewById(R.id.root_container):
// and according to your preference you can set
root.setKeepScreenOn(true/false);
offical doc dit
/**
* Controls whether the screen should remain on, modifying the
* value of {@link #KEEP_SCREEN_ON}.
*
* @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}.
*
* @see #getKeepScreenOn()
*/
Pour plus référence s'il vous plaît suivre this lien
effacer votre drapeau –