我知道这可能是重复的帖子,但我还没有得到确切的答案,请告诉我是否有人知道这一点。
我的需要是我想在我的Android应用程序中创建暗淡的scrren功能假设我的应用程序理想30秒所以我的屏幕应该变暗,如果我触摸屏幕那么屏幕再次变亮请帮助我
最佳答案
int Time_delay=30000;
Runnable screentimeout= new Runnable()
{
public void run()
{
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 1.0f;
getWindow().setAttributes(lp);
}
}
30秒后屏幕亮度将变暗。 这将帮助您检测 Activity 之间的用户交互 在您的 Activity 中
Handler hl_timeout = new Handler();
@Override
public void onCreate(Bundle b)
{
hl_timeout.postDelayed(screentimeout, Time_delay); // The screentimeout will be triggered after 30sec
}
有一个功能可以检测用户交互。使用它
@Override
public void onUserInteraction() {
// TODO Auto-generated method stub
hl_timeout.removeCallbacks(screentimeout);
hl_timeout.postDelayed(screentimeout, Time_delay);
}
关于android - Android中如何根据时间调暗屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20334652/