繁体   English   中英

Xamarin.Android TextView 禁用 - SetFocusable 或 Clickable?

[英]Xamarin.Android TextView disable - SetFocusable or Clickable?

我有一个链接到另一个活动的 TextView。 我想根据特定条件禁用它。

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.我尝试将 0 和 ViewFocusability.NotFocusable 作为值,但都不起作用。

C#:

textView.SetFocusable(ViewFocusability.NotFocusable);


textView.SetFocusable(0);

然后我查看了 MS 文档,我看到了一个属性“可点击”。所以我尝试了:

textView.Clickable = false;

现在这行得通。 这是最合适的方法吗?

TextView 是一个不能点击和编辑的视图。 我在我的项目中尝试了很多次。 我使用以下代码:

<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. 此外, android:focusableInTouchMode="true"使 textview 可以对焦,当用户点击它时,软键盘将显示。

但如果我将启用设置为 false,则 textview 将被禁用。 它不能被点击和输入任何方式。 所以textview.Enabled = false; 可能是你想要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM