繁体   English   中英

setEnabled(false) 时显示 TextInputEditText 错误

[英]Show TextInputEditText error when setEnabled(false)

我目前有一个 TextInput,一旦选择了微调器位置,它就会显示所需的计数作为错误。 该部分有效,但我还希望在仍需要选择位置时显示错误。 当我使 TextInput 不可编辑时,错误不会显示并且我看不到或单击它。 我尝试使用 setFocusable(),但这允许编辑文本。

    if (curr_position != 0) {
        quantity_field.setEnabled(true);
        quantity_field.requestFocus();
        quantity_field.setError(quantities[parent.getSelectedItemPosition()]);
    } else {
        quantity_field.setError("Select location first.");
        quantity_field.setEnabled(false);
    }

本质上,我想禁用除错误之外的 TextInput 的所有部分。

您是否尝试过将您的app:errorEnabled="true"设置为TextInputLayout的属性,并从 xml 文件中将 clickable、cursorVisible、focusable、focusableInTouchMode 设置为 false?

<android.support.design.widget.TextInputLayout
    android:id="@+id/quantity_field"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:errorEnabled="true">

    <android.support.design.widget.TextInputEditText
        android:id="@+id/quantity_input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="false" 
        android:cursorVisible="false" 
        android:focusable="false" 
        android:focusableInTouchMode="false"
        android:hint="Location:" />

</android.support.design.widget.TextInputLayout>

代码:

if (curr_position != 0)
    quantity_field.setError("Select location first.");
else
    quantity_field.setError(null); // hides the error and reset the tint

暂无
暂无

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

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