I have a TextView that links to another activity. I want to disable it based on a certain condition.
I see their are plenty of articles on disabled EditText for Xamarin.Android, but not a lot for disabling a clickable TextView (mainly just for Java Android, not Xamarin.Android (c#). One instruction I found said to use the method SetFocusable. I tried both 0, and ViewFocusability.NotFocusable as values, but neither work.
C#:
textView.SetFocusable(ViewFocusability.NotFocusable);
textView.SetFocusable(0);
I then look at the MS documentation, and I see a property "Clickable. So I tried:
textView.Clickable = false;
Now this works. Is this the most appropriate way to do this?
TextView is a view which can't be clicked and edited. I tried many times in my project. And I use the following code:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"
android:focusableInTouchMode="true"
android:layout_gravity="center"
android:textSize="23dp"
android:id="@+id/textView1"
android:clickable="true"
android:focusable="true"
android:editable="true"
android:enabled="false"
/>
The android:clickable="true"
, android:focusable="true"
and android:editable="true"
make the textview can be input from the physical keyboard but it still can't be focused. In addition, the android:focusableInTouchMode="true"
make the textview can be focused and when user click it, the soft keyboard will show.
But if I set the enable as false, the textview is disabled. It can't be clicked and input any way. So the textview.Enabled = false;
may be you want.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.