Android studio EditText显示光标
时间: 2024-02-17 22:08:18 浏览: 38
在 Android Studio 中的 EditText 中显示光标,可以通过设置 EditText 的 `android:backgroundTint` 属性和 `android:textCursorDrawable` 属性来实现。具体操作如下:
1. 在 EditText 中添加 `android:backgroundTint` 属性,设置为你想要的颜色。
```xml
<EditText
...
android:backgroundTint="#FF4081" />
```
2. 在 res 目录下创建一个 drawable 目录,在其中创建一个 xml 文件,命名为 cursor_drawable.xml。
3. 在 cursor_drawable.xml 文件中添加以下代码:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="2dp" />
<solid android:color="#FF4081" />
</shape>
```
此处的 `android:color` 属性为光标的颜色,可以根据需要自行修改。
4. 在 EditText 中添加 `android:textCursorDrawable` 属性,指向上面创建的 cursor_drawable.xml 文件。
```xml
<EditText
...
android:textCursorDrawable="@drawable/cursor_drawable" />
```
完成以上操作后,运行程序,即可在 EditText 中看到光标了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)