Dim screen while user inactive

前端 未结 3 1947
长情又很酷
长情又很酷 2021-01-11 18:46

I have an app which is used for lets say 4 hours, but only every 5 minutes a user needs to make an input or read the screen. Putting the phone to sleep and locking the scre

3条回答
  •  Happy的楠姐
    2021-01-11 19:27

    You can use:

    WindowManager.LayoutParams lp = getWindow().getAttributes();  
    lp.dimAmount=1.0f; 
    getWindow().setAttributes(lp);  
    

    to dim/undim the screen when you want to.

    lp.dimAmount=1.0f will dim the screen totally but you can set it at your will with values from 0 (no dim at all) to 1.0f.

    You can set a timer to call this after 5 minutes of inactivity and then turn the screen "back on" on any touch event or such maybe.

提交回复
热议问题