【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"/>
相关推荐
三少爷的鞋3 分钟前
Android 协程时代,Handler 应该退休了吗?
android
火柴就是我14 小时前
让我们实现一个更好看的内部阴影按钮
android·flutter
我和你共同17 小时前
openClaw本地部署全流程
aigc·openai·cursor
砖厂小工20 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心21 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心21 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker1 天前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴1 天前
Android17 为什么重写 MessageQueue
android
阿巴斯甜2 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker2 天前
实战 Compose 中的 IntrinsicSize
android·kotlin