Android 如果背景颜色为特定类型,则禁用单击
我正在努力实现标题中提到的目标。如果我的布局的背景色是F0,那么点击应该被禁用。大概是这样的:Android 如果背景颜色为特定类型,则禁用单击,android,clickable,Android,Clickable,我正在努力实现标题中提到的目标。如果我的布局的背景色是F0,那么点击应该被禁用。大概是这样的: final RelativeLayout row = (RelativeLayout) fragmentView.findViewById(R.id.row); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItem
final RelativeLayout row = (RelativeLayout) fragmentView.findViewById(R.id.row);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long mallId) {
//disable click if background color is #F0F0F0
if(row.getBackground() is #F0F0F0){
//do nothing
}
else {
Intent intent = new Intent(getActivity(), ShopActivity.class);
intent.putExtra("MALL_ID", (int) mallId);
startActivity(intent);
}
}
});
XML
试试这个:
ColorDrawable colorDrawable=(ColorDrawable)row.getBackground();
if( colorDrawable.getColor() != 0xF0F0F0){
//do your work.
}
您可以通过以下代码获得视图的背景色ColorDrawable buttonColor=ColorDrawable row.getBackground;然后通过检查条件u可以启用或禁用click@Nithinlal但是我怎么能把它和十六进制比较呢value@stud91请看下面我的答案;
if( ((ColorDrawable)row.getBackground()).getColor() == Color.parseColor("#F0F0F0")){
//do nothing
}
else{
//...
}
ColorDrawable colorDrawable=(ColorDrawable)row.getBackground();
if( colorDrawable.getColor() != 0xF0F0F0){
//do your work.
}