Android setColorFilter 不更新按钮
我有一个按钮,它有:
.setClickable(false);
并
.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
在初始化时。
然后,我等待 GPS 信号,当找到信号时,我将 setClickable 设置为 true,并将 ColorFilter 设置为 null。这确实有效,但不会更新按钮,除非触摸屏幕的任何地方。
我确信这不是 GPS 代码中的循环错误,因为一旦按下此按钮,另一个按钮将被设置为可点击且过滤器为空,但会发生完全相同的事情。
以前有人经历过这种情况吗?它发生在 2.2 和 2.3
下面是按钮的动作监听器的示例:
setgps1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(!gps1set)
{
gps1set = true;
setgps1.setText("Reset");
latitude1.setText(latitude1.getText()+ " +/-"+gpsaccuracy+"m");
longitude1.setText(longitude1.getText()+ " +/-"+gpsaccuracy+"m");
altitude1.setText(altitude1.getText() + " +/-"+gpsaccuracy+"m");
latitude1.setTextColor(Color.GREEN);
longitude1.setTextColor(Color.GREEN);
altitude1.setTextColor(Color.GREEN);
save.setClickable(true);
save.getBackground().setColorFilter(null);
}
else
{
gps1set = false;
setgps1.setText("Set GPS 1");
latitude1.setText(""+lat1);
longitude1.setText(""+lon1);
altitude1.setText(""+alt);
latitude1.setTextColor(Color.WHITE);
longitude1.setTextColor(Color.WHITE);
altitude1.setTextColor(Color.WHITE);
save.setClickable(false);
save.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
}
}
});
I have a button that is has:
.setClickable(false);
and
.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
upon initialization.
I then wait for a GPS signal and when one is found, i set setClickable to true and the ColorFilter to null. This does work, but does not update the button unless the screen is touched anywhere.
I am certain that this not some loop error in the GPS code because once this button is then pressed, another is set to become clickable and the filter to null, yet the exact same thing happens.
Anyone ever experienced this before? It happens in both 2.2 and 2.3
Heres a sample of the actionlistener of the button:
setgps1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(!gps1set)
{
gps1set = true;
setgps1.setText("Reset");
latitude1.setText(latitude1.getText()+ " +/-"+gpsaccuracy+"m");
longitude1.setText(longitude1.getText()+ " +/-"+gpsaccuracy+"m");
altitude1.setText(altitude1.getText() + " +/-"+gpsaccuracy+"m");
latitude1.setTextColor(Color.GREEN);
longitude1.setTextColor(Color.GREEN);
altitude1.setTextColor(Color.GREEN);
save.setClickable(true);
save.getBackground().setColorFilter(null);
}
else
{
gps1set = false;
setgps1.setText("Set GPS 1");
latitude1.setText(""+lat1);
longitude1.setText(""+lon1);
altitude1.setText(""+alt);
latitude1.setTextColor(Color.WHITE);
longitude1.setTextColor(Color.WHITE);
altitude1.setTextColor(Color.WHITE);
save.setClickable(false);
save.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人到达这里...您必须调用:
在更新的 api 中更改背景后。
If anyone arrived here... you have to call:
after changing the background in newer apis.