Android 如何在片段中显示错误文本?
我正在使用Android 如何在片段中显示错误文本?,android,android-fragments,Android,Android Fragments,我正在使用setError设置EditText错误消息,例如: editTextName.setError("Please enter your name"); editTextName.requestFocus(); 当文本视图位于“活动”本身时,上述操作有效,即显示错误图标和文本气球 但是,当文本视图位于片段中时,仅显示错误图标 显示错误文本气球的正确步骤是什么 yourEdittext.setError("This field is required"); yourEdittext.re
setError
设置EditText
错误消息,例如:
editTextName.setError("Please enter your name");
editTextName.requestFocus();
当文本视图位于“活动”本身时,上述操作有效,即显示错误图标和文本气球
但是,当文本视图位于片段中时,仅显示错误图标
显示错误文本气球的正确步骤是什么
yourEdittext.setError("This field is required");
yourEdittext.requestFocus();
您应该为此调用请求焦点以使其工作。希望这有帮助
<android.support.design.widget.TextInputLayout
android:layout_below="@+id/email_holder"
android:id="@+id/password_holder"
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>
尝试像上面那样添加布局。当文本视图位于片段中时,只显示错误图标,这不应该发生。我确实有
requestFocus()
,但它仍然不起作用。它在使用TextInputLayout时起作用,但它基于新的材质设计。我将它标记为应答,因为现在可以看到错误消息。