Cha*_*eon 5 android android-layout
我计划进行后台服务,这将使屏幕闪烁/闪烁,直到用户触摸屏幕.
我不知道如何使屏幕闪烁的方法 - 只有通过生成活动可以通过亮度和控制来学习的方法.
想要在屏幕上进行闪烁换色,即黑白或屏幕开/关,使其比亮度更明显.
Aer*_*row 12
我用它来屏幕闪烁,在这段代码中我的relativeLayout(HomeLayout)会闪烁.
Animation animation = new AlphaAnimation(1, 0); // Change alpha
// from fully
// visible to
// invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator()); // do not alter
// animation
// rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation
// infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at
// the
// end so the layout will
// fade back in
relativeLayout.startAnimation(animation);
Run Code Online (Sandbox Code Playgroud)
当您触摸scree或按钮以清除动画时,添加此代码.
relativeLayout.clearAnimation();
Run Code Online (Sandbox Code Playgroud)
从您的服务中,您可以与WakeLock:
获取WakeLock:
PowerManager powerMan = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerMan.newWakeLock(
PowerManager.SCREEN_DIM_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "wakelockTag");
Run Code Online (Sandbox Code Playgroud)
然后打开屏幕:
wakeLock.acquire();
Run Code Online (Sandbox Code Playgroud)
然后再次将其关闭:
wakeLock.release();
Run Code Online (Sandbox Code Playgroud)
您可以将其放入Thread睡眠中或使用 aTimer来创建闪光灯。
例如:
new Thread() {
public void run() {
boolean screenOn = false;
for (int i = 0; i < 5; i++) {
try {
sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (screenOn) {
wakeLock.acquire();
} else {
wakeLock.release();
}
}
}
}.run();
Run Code Online (Sandbox Code Playgroud)
它不会是黑/白,只是开/关。
如果你想变成黑/白,你还必须松开KeyLock(查找Android Keyguard),然后按下Activity完全黑色的按钮,然后像以前一样将 a或 a 中的按钮更改Activity为白色。还有很多工作。TimerThread
请记住在以下位置获得许可AndroidManifest.xml:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Run Code Online (Sandbox Code Playgroud)
KeyGuard如果您沿着这条路线走下去,则需要额外的权限才能解锁。