如何在 android 中更改 EditText 气泡颜色(在光标下)?

How to change EditText bubble color (under cursor) in android?

如何在 android 中更改 EditText 气泡的颜色,我可以更改可绘制的光标,但我想更改气泡的颜色,请分享想法。

参考截图:

如有任何帮助,我们将不胜感激。

更改 res/values/styles.xml 中的颜色。气泡使用 colorAccent:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <!-- Other theme overrides here -->
    <item name="colorAccent">@color/Gray2</item>
</style>

在上面的 <item name="colorAccent">@color/Gray2</item> 行中,您可以在其中放置您想要的气泡颜色。

您可以更改所有 EditText 气泡和栏 colors 设置 AppTheme 中的强调色。

<style name="AppTheme" parent="Base.Theme.AppCompat.Light">
    <item name="colorPrimary">@color/indigo</item>
    <item name="colorAccent">@color/pink</item>
</style>

或者您可以只用组件的 android:theme 属性更改一个 EditText

<style name="MyEditText" parent="Theme.AppCompat.Light">  
   <item name="colorControlNormal">@color/indigo</item>
   <item name="colorControlActivated">@color/pink</item>
</style>  

<EditText  
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Hint text"
    android:theme="@style/MyEditText"
    />

http://developer.android.com/training/material/theme.html#ColorPalette

<resources>
  <!-- inherit from the material theme -->
  <style name="AppTheme" parent="android:Theme.Material">
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="android:colorPrimary">@color/primary</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">@color/accent</item>
  </style>
</resources>

并检查这个:主题 UI 控件像 checkboxestext fields

<!--   theme UI controls like checkboxes and text fields -->
        <item name="android:colorAccent">@color/accent</item>

有那么难找吗? :)

您需要更改您的主题 colorControlActivated 颜色。

源代码:Android 源代码中 text_select_handle 的默认实现。

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/text_select_handle_middle_mtrl_alpha"
android:tint="?attr/colorControlActivated" />

您应该更改 "colorAccent" 并且为了不更改整个应用程序的此参数,您可以使用 ThemeOverlay。更详细的可以看this article,最后一个主题"Cursor and Selection"