设置为Enabled(false)时显示TextInputEditText错误



我目前有一个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

最新更新