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

2023-04-22  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读