java - setEnabled(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
推荐阅读
- wpf - 在.Net Core中添加值后如何刷新WPF数据网格
- wordpress - 如何在跨域(iframe)和同源场景中登录wordpress?
- wordpress - 条纹 Wordpress 发票
- cygwin - 我想在 Cygwin64 上构建 cgreen
- ios - UniversalLink 不适用于 iOS 14 设备,但在模拟器上运行良好
- angular - 为什么 agular 材料排序显示箭头但不对列进行排序?
- android - 谷歌登录按钮定制设计android
- python - Python:尝试访问日期时间对象中的小时、分钟、秒
- python - “RuntimeError: No surface found at the given iso value” 将 3d numpy 数组转换为网格时出错
- python - 如何在烧瓶中使用后台线程?