【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"/>
相关推荐
东坡大表哥7 小时前
【Ubuntu】Ubuntu 20.04 LTS → 22.04 LTS 升级实录
android·linux·ubuntu
不要试图纠正别人9 小时前
IdleHandler 一次都不跑,问题不在主线程忙
android·性能优化
booboosui9 小时前
记忆装不下时谁删:500 条上限与每回合十行索引
android
好的佩奇1 天前
Dart 之 JSON
android·flutter·dart
_祝你今天愉快1 天前
Android 事件传递机制:[一] 事件分发机制详解
android
Digitally1 天前
如何将电脑上的联系人传输到安卓手机(4 种方法)
android
Carson带你学Android1 天前
移动开发周报 :一句话出 App、低端机跑 Gemini、手机写代码
android·ai编程
恋猫de小郭2 天前
站起来,Flutter 要支持真正的 3D Texture 了
android·前端·flutter
FungLeo2 天前
FengCMS · PHP+MySQL 升级实录 · 留言模块的六项问题:未审核进公开列表、旧回复覆盖、批量删除恢复
android·mysql·php·工程实践·fengcms
洞见前行2 天前
Android 架构演进全解:从 MVC、MVP、MVVM 到 MVI 的原理、代码实战与得失权衡
android·架构·kotlin