【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"/>
相关推荐
booboosui3 分钟前
录一遍就会:8 种步骤、6 类失败,卡住时只修那一步
android
阿杰m11 分钟前
Android源码第十五章:Camera2 与 CameraService——一帧图像怎样回到应用
android
恋猫de小郭6 小时前
Flutter Analyzer 系列坑推进,必看,AI 时代这玩意最吃你内存
android·前端·flutter
LinXunFeng17 小时前
拿竞品 App 一扫,技术栈全暴露了
android·flutter·开源
Gracker20 小时前
AIW:从系统机制到性能排查,一本可以对照源码的 Android 电子书
android
三少爷的鞋20 小时前
代码越来越便宜,判断力越来越贵:AI 时代的 Android 架构与协程避坑指南
android
Gracker1 天前
SmartPerfetto 1.19.0:换过分析引擎之后,这次更新了什么
android
HQL_seven1 天前
【Android】BroadcastReceiver 详解
android
_祝你今天愉快1 天前
Paint Cavans高级绘制:[二] Paint-滤镜,XFERMODE
android
小乖写代码1 天前
字段获取代码(Android) · Android Input Examples
android·whatsapp·账号注册