首先,你需要将屏幕的亮度存储在某个变量 例如闪烁之前漂浮
float oldBrightNess = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS);
当状态为假将该值设置为窗口的布局。
请参阅下面的代码,它的工作方式完全相同。 如果没有闪现在大屏幕则clickin上的按钮会闪烁,反之亦然,当你再次
示例代码单击
public class RelativeLayoutTesting extends Activity implements OnClickListener {
Button button3;
boolean isPLAYING;
MediaPlayer mp;
boolean isFlashedBefore = false;
float oldBrightNess = 0;
float newBrightNess = 1.0f;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sample);
button3 = (Button) findViewById(R.id.btn3);
button3.setOnClickListener(this);
try{
oldBrightNess = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS);
}catch(Exception ex){
ex.printStackTrace();
oldBrightNess = 1.0f;
}
System.out.println("...Brighness..."+oldBrightNess);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
WindowManager.LayoutParams lp = getWindow().getAttributes();
if(!isFlashedBefore){
lp.screenBrightness = newBrightNess;
}else{
lp.screenBrightness = oldBrightNess;
}
getWindow().setAttributes(lp);
isFlashedBefore = !isFlashedBefore;
// emailWOAttach(RelativeLayoutTesting.this);
}
}
不工作。我正在处理器线程上重复执行屏幕闪烁动画。当我恢复它不起作用。屏幕变黑。 –