【问题标题】:In Android Studio how to change the cursor?在 Android Studio 中如何更改光标?
【发布时间】:2019-05-20 12:13:26
【问题描述】:

** 通过使用 xml 或设计,当我开始在纯文本中写入时,我想将光标的颜色从默认颜色更改为另一种颜色。请问我该怎么做**

【问题讨论】:

标签: android android-studio cursor selector


【解决方案1】:

简单的方法(对于 API 级别>=21)

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

    <item name="colorControlActivated">@color/your_cursor_color</item>
</style>

更好的方法(适用于所有 API 级别)

1.在布局中定义android:textCursorDrawable

<EditText  
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textCursorDrawable="@drawable/color_cursor"
    />

2.在drawable中创建光标

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="2.5dp" />
    <solid android:color="color_cursor"  />
</shape>

【讨论】:

    猜你喜欢
    • 2021-10-08
    • 2022-06-29
    • 2022-01-03
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 2016-04-04
    • 2011-11-24
    • 1970-01-01
    相关资源
    最近更新 更多