【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"/>
相关推荐
RATi GORI7 小时前
MySQL中的CASE WHEN语句:用法、示例与解析
android·数据库·mysql
MoFe18 小时前
【Mysql】创建IP授权用户并授权
android
冬奇Lab9 小时前
Camera2 API架构基础:Android视频系统的大门
android·音视频开发·源码阅读
hnlgzb9 小时前
安卓app kotlin语法,Hilt是什么东西?
android·开发语言·kotlin
Android系统攻城狮11 小时前
Android tinyalsa深度解析之pcm_params_get_periods_min调用流程与实战(一百七十三)
android·pcm·tinyalsa·音频进阶手册
Xempastissimo12 小时前
Android常见界面控件
android
法欧特斯卡雷特12 小时前
从 Kotlin 编译器 API 的变化开始: 2.3.20
android·后端·开源
词元Max13 小时前
1.5 Harness 架构深度解析:Claude Code 为什么强?
android·架构
yy552713 小时前
Mysql 主从复制与读写分离
android·数据库·mysql
zhenxin012214 小时前
万字详解 MySQL MGR 高可用集群搭建
android·mysql·adb