如果背景颜色属于特定类型,则禁用点击
Disable click if background color is of a particular type
我正在努力实现标题中提到的。如果我的布局的背景颜色是 #F0F0F0
那么点击应该被禁用。像这样:
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
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0F0F0"
android:paddingBottom="7dp">
...
</RelativeLayout>
if( ((ColorDrawable)row.getBackground()).getColor() == Color.parseColor("#F0F0F0")){
//do nothing
}
else{
//...
}
试试这个:
ColorDrawable colorDrawable=(ColorDrawable)row.getBackground();
if( colorDrawable.getColor() != 0xF0F0F0){
//do your work.
}
我正在努力实现标题中提到的。如果我的布局的背景颜色是 #F0F0F0
那么点击应该被禁用。像这样:
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
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0F0F0"
android:paddingBottom="7dp">
...
</RelativeLayout>
if( ((ColorDrawable)row.getBackground()).getColor() == Color.parseColor("#F0F0F0")){
//do nothing
}
else{
//...
}
试试这个:
ColorDrawable colorDrawable=(ColorDrawable)row.getBackground();
if( colorDrawable.getColor() != 0xF0F0F0){
//do your work.
}