我们可以在 Edittext 中成功设置错误,但在 textview 中设置失败。有什么问题吗?? 我试过了
((TextView) findViewById(R.id.df)).requestFocus();
((TextView) findViewById(R.id.df)).setSelected(true);
((TextView) findViewById(R.id.df)).setError("akjshbd");
但我没有弹出错误消息。
最佳答案
默认 TextView 不可聚焦。所以,你需要设置 android:focusable="true" 和 android:focusableInTouchMode="true"。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
而且不需要设置 setSelected(true)。
((TextView) findViewById(R.id.df)).requestFocus();
((TextView) findViewById(R.id.df)).setError("akjshbd");
关于Android setError ("error") 在 Textview 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13508270/