You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android开发:如何修改EditText的橙色布局颜色?

Android开发:修改EditText橙色高亮部分颜色

EditText橙色高亮效果

请问在Android开发中,如何修改EditText控件的橙色部分颜色?


方法1:通过主题样式修改(全局/单个控件)

如果要统一修改APP内所有EditText的样式,或者单独定制某个EditText的样式,可在styles.xml中定义自定义样式:

<style name="CustomEditTextStyle" parent="Widget.AppCompat.EditText">
    <!-- 调整焦点状态下的下划线颜色 -->
    <item name="colorAccent">#你的目标颜色</item>
    <!-- 调整文本选中时的高亮背景色 -->
    <item name="colorControlActivated">#你的目标颜色</item>
</style>

给布局中的EditText应用该样式:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/CustomEditTextStyle"/>

若要全局生效,将样式配置到App主题的editTextStyle属性中:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="editTextStyle">@style/CustomEditTextStyle</item>
</style>

方法2:直接在布局中设置属性

针对单个EditText,可直接在布局文件里添加以下属性(需使用AppCompat库):

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:colorAccent="#你的目标颜色"
    app:colorControlActivated="#你的目标颜色"/>

方法3:单独修改文本选中高亮色

如果只需要调整文本选中时的橙色高亮背景,不需要修改下划线颜色,可使用android:textColorHighlight属性:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColorHighlight="#你的目标颜色"/>

内容的提问来源于stack exchange,提问作者Danison Auza Nuñez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 04:09:22