【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"/>
相关推荐
Libraeking19 分钟前
视觉篇:Canvas 自定义绘图与高级动画的华丽圆舞曲
android·经验分享·android jetpack
Fushize1 小时前
多模块架构下的依赖治理:如何避免 Gradle 依赖地狱
android·架构·kotlin
Jomurphys2 小时前
Kotlin - 类型别名 typealias
android·kotlin
Haha_bj2 小时前
Flutter ——flutter_screenutil 屏幕适配
android·ios
Haha_bj2 小时前
Flutter ——device_info_plus详解
android·flutter·ios
前端小伙计2 小时前
Android/Flutter 项目统一构建配置最佳实践
android·flutter
bryceZh2 小时前
Agent-Skills使用指南
agent·cursor
Mr_sun.4 小时前
Day09——入退管理-入住-2
android·java·开发语言
ujainu5 小时前
告别杂乱!Flutter + OpenHarmony 鸿蒙记事本的标签与分类管理(三)
android·flutter·openharmony
常利兵5 小时前
Android内存泄漏:成因剖析与高效排查实战指南
android