Correct method for setKeepScreenOn / FLAG_KEEP_SCREEN_ON

后端 未结 5 1905
灰色年华
灰色年华 2020-12-02 16:10

I am using the method setKeepScreenOn(true) and haven\'t been able to figure out how to call this in relation to the current Activity (which has a content view set). I\'ve

5条回答
  •  死守一世寂寞
    2020-12-02 16:34

    According to Google Docs for android Developers you've two ways to do this :

    First way :

    public class MainActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
    

    Second way is to add in your xml file layout this attribute: android:keepScreenOn="true"

提交回复
热议问题