【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"/>
相关推荐
.豆鲨包20 分钟前
【Android】Binder机制浅析
android·binder
Nerve2 小时前
GooglePay: API 文档
android·google
Nerve2 小时前
GooglePay: 订阅商品购买流程
android·google
summerkissyou19872 小时前
Audio-触摸音-播放流程
android
Nerve2 小时前
GooglePay: 消耗商品购买流程
android·google
LiteHeaven3 小时前
Android 8.1 Unable to create application data 问题分析
android
Nerve3 小时前
GooglePay: 一个基于 Google Play Billing Library 封装的 Android 支付库
android·google
Nerve3 小时前
Google Play 结算系统入门指南
android·google
青莲8434 小时前
Android Jetpack - 2 ViewModel
android·前端