String comparison on Android Data Binding

It can be do in two way :-

1. First way inside xml :-

    android:textColor="@{notice.action.equals(`continue`) ? @color/enabledPurple : @color/disabledGray }"

2. Second way (programatically) Inside xml :-

app:setColor="@{notice.action}" 
inside activity or custom class : -    
    @BindingAdapter("setColor")
        public static void setTextColor(TextView textView, String s) {

             Context context = textView.getContext();

        textView.setTextColor(s.equals("continue") ? context.getResources().getColor(R.color.enabledPurple) : context.getResources().getColor(R.color.disabledGray));
        }

Leave a Comment