【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 天前
Android插件化原理与方案详解
android
惟恋惜1 天前
Jetpack Compose 界面元素状态(UI Element State)详解
android·ui·android jetpack
_李小白1 天前
【Android FrameWork】延伸阅读:IGraphicBufferProducer驱动UI绘制过程
android·ui
weixin_462446231 天前
Kali/ubuntu Linux 中彻底删除 Cursor 编辑器(含 dpkg 非空目录警告解决)
linux·ubuntu·cursor
_李小白1 天前
【Android FrameWork】第二十八天:Activity 的 UI 绘制全过程
android·ui
_李小白1 天前
【Android FrameWork】第三十天:Surface创建流程解析
android
元亓亓亓1 天前
考研408--操作系统--day8--操作系统--虚拟内存&请求分页&页面置换/分配
android·java·开发语言·虚拟内存
有位神秘人1 天前
Android的Compose系列之文本TextView
android
Engineer-Jsp1 天前
Flutter 开发 Android 原生开发神器 flutter_api_stub
android·flutter