我有一个应用程序,我处理所有的触摸,而不是使用触摸和手势检测app,因为它是一个浮动窗口,是唯一的方式工作。
我所做的事情之一就是改变手指下视图的颜色。OnTouch我检查哪个视图在手指下面,如果它与我之前运行的视图不同:
myView.setBackgroundColor(getResources().getColor(R.color.white));当我到达当前的视图并很快返回时,它就不起作用了。
我用日志检查过它,发现的视图是正确的。我也检查过了,并执行了setBackgroundColor所在的行。
所以我不知道还能做什么。是否有setBackgroundColor不工作的情况?是因为如果onTouch花费太多的时间来执行它的任务吗?
知道怎么解决这个问题吗?
编辑:只有当我转到当前的视图并快速返回时,才会失败。我没有添加代码,因为我认为它比我所做的抽象更难阅读。我已经把它清理干净并贴了出去。如果您认为任何被调用的方法是相关的,我可以添加它们。编辑2:如果操作不是ACTION_DOWN或ACTION_UP运行的代码。这些案件与此无关。
if ((isPortrait && isPortraitMeasured) || (!isPortrait && isLandscapeMeasured)) {
//Log.d("algor", "Here calculate where it is");
final int lastCol = currentColumn;
final int lastRow = currentRow;
findCell((int) event.getRawX(), (int) event.getRawY());
if ((lastCol == currentColumn && lastRow == currentRow)) {
if (isPortrait && currentRow==-1 || (!isPortrait && currentColumn==-1)
&& !wasPressed && currentTable!=mainTable) {
//is actionBar. Check if finger is over back icon, to go back
//Code not related to the problem...
}
} else {
int currentIndex = getAppsListIndex();
if (currentIndex >= 0) {
View nextApp;
if (isPortrait)
nextApp = cellsP.get(currentTable).get(currentIndex);
else
nextApp = cellsL.get(currentTable).get(currentIndex);
final Object tag = nextApp.getTag();
if (tag instanceof FolderData) {
//Code not related to the problem...
} else {
Log.d("fastf", "time to change color");
//nextApp.setBackgroundColor(getResources().getColor(R.color.white));
nextApp.setBackgroundColor(whiteColor);
//nextApp.setBackground(getResources().getDrawable(R.color.white));
/*final View app = nextApp;
app.post(new Runnable() {
@Override
public void run() {
app.setBackgroundColor(getResources().getColor(R.color.white));
}
});*/
}
} else {
//Code not related to the problem...
}
int lastIndex = getAppsIndexFromInts(lastRow, lastCol);
//lastCol != -2 is because otherwise, on opening the launcher it animates
// the last app launched
if (lastIndex >= 0 && lastCol != -2) {
View lastApp;
if (isPortrait)
lastApp = cellsP.get(currentTable).get(lastIndex);
else
lastApp = cellsL.get(currentTable).get(lastIndex);
ObjectAnimator animator = ObjectAnimator.ofInt(lastApp,
"backgroundColor", getResources().getColor(R.color.clear_gray),
getResources().getColor(R.color.white_overlay_transition));
animator.setDuration(500);
animator.setEvaluator(new ArgbEvaluator());
animator.start();
}
}
}发布于 2016-08-19 09:00:30
你应该用
NextApp.setBackgroundResource(.)而不是其他人。
因为你的"R.color.white“是一个资源。
祝您今天愉快。
这是个老问题,但我也面临着同样的问题,于是我解决了这个问题。
发布于 2014-09-04 12:39:08
试试看
myView.setBackground(getResources().getDrawable(R.color.white));
发布于 2014-09-04 12:55:05
myView.setBackgroundColor(getResources().getColor(R.color.bgcolor));color.xml
<color name="bgcolor">#ffffff</color>https://stackoverflow.com/questions/25665401
复制相似问题