【Android】设置光标颜色和图标

创建主题

该主题可以更改文字下方拖拽手柄的颜色

xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="RedTextCursor">
    <item name="android:colorControlActivated">#FF0000</item>
  </style>
</resources>
应用主题到Dialog/PopupWindow/DialogFragment/Activity

根据组件类型,使用对应的主题设置方式

kotlin 复制代码
class MyDialog : Dialog(context, R.style.RedTextCursor)
创建光标资源

用于改变光标颜色和形状

xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size android:width="@dimen/dp_2" />
    <solid android:color="@color/primary_200" />
</shape>
设置TextView光标
xml 复制代码
<TextView
	android:textCursorDrawable="@drawable/shape_cursor_red"/>
相关推荐
方白羽1 天前
SP vs DataStore:解锁 Android 本地存储的并发秘密
android·app·客户端
GY-931 天前
【Android】View和Componse
android
王二蛋与他的张大花1 天前
后台内存 827MB,我一行业务逻辑都没改就砍到 100MB
android·flutter·性能优化
Paper_Love1 天前
android安全公告网站
android
StarsGreen1 天前
Android ADB(Android Debug Bridge)命令详解
android
阿健君1 天前
现代 Android 屏幕适配完全指南
android·kotlin
软件交付观察室1 天前
用户关掉手机定位权限后,原生App还能显示哪些位置?
android·ios·移动开发
黄林晴1 天前
Jetpack Compose 1.13.0 来了:大量 API 弃用,表单代码要重构
android·android jetpack
黄林晴1 天前
Kotlin Toolchain 太牛了!一个提示词就能构建 KMP 双端应用
android·kotlin
黄林晴1 天前
KMP 跨端共享资源别踩坑!composeResources 看着香,上线容易翻车
android