Zhe*_*Liu 5 android android-edittext
我有一个 editText 当前显示错误弹出窗口。
editText.setError("你做错了什么");
现在我需要一个工作流程,这样当用户单击其他地方的按钮时,我需要在 editText 上设置错误。但现在,只显示一个错误图标。
我的问题是,是否可以使其显示整个错误文本,而无需用户实际单击(聚焦)它?
解决方案1
称呼
editText.requestFocus()
Run Code Online (Sandbox Code Playgroud)
在设置错误之前。
解决方案2
使用文本输入布局。
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
并在代码中
textInputLayout.setError("Error");
Run Code Online (Sandbox Code Playgroud)
解决方案3
自定义视图,由您决定。