美文网首页
EditText去掉焦点光标——最好用的办法

EditText去掉焦点光标——最好用的办法

作者: 风就那么大 | 来源:发表于2023-04-22 15:11 被阅读0次

开发Android程序时,EditText在编辑完成后,点击保存时,需要去掉光标以告诉用户保存成功了。我发现最好的办法是, 在当前布局文件任意位置,加LinearLayout,让LinearLayout可以得到焦点。布局代码如下:

 <LinearLayout                  
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="true"
                android:focusableInTouchMode="true"/>

这里重点是android:focusable=“true” 和 android:focusableInTouchMode=“true” 让LinearLayout 能得到焦点。

java代码中,用LinearLayout对象调用 .requestFocus() 方法得到焦点, 这样edittext的焦点就去掉了;

原文链接:https://blog.csdn.net/bluecat333/article/details/99690933

相关文章

网友评论

      本文标题:EditText去掉焦点光标——最好用的办法

      本文链接:https://www.haomeiwen.com/subject/bamsjdtx.html