【问题标题】:How to change EditText bubble color (under cursor) in android?如何在 android 中更改 EditText 气泡颜色(光标下)?
【发布时间】:2016-05-22 03:29:04
【问题描述】:

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

参考截图:

任何帮助将不胜感激。

【问题讨论】:

标签: android colors android-edittext drawable text-cursor


【解决方案1】:

您可以更改所有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"
    />

【讨论】:

【解决方案2】:

更改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>

在上面的&lt;item name="colorAccent"&gt;@color/Gray2&lt;/item&gt; 是您为气泡添加所需颜色的行。

【讨论】:

    【解决方案3】:

    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>
    

    很难找到吗? :)

    【讨论】:

      【解决方案4】:

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

      source: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" />
      

      【讨论】:

        【解决方案5】:

        您应该更改“colorAccent”,并且为了不更改整个应用程序的此参数,您可以使用 ThemeOverlay。更详细的可以阅读this article,最后一个主题“游标与选择”

        【讨论】:

          猜你喜欢
          • 2020-05-26
          • 2017-04-14
          • 1970-01-01
          • 2012-07-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-11-25
          • 1970-01-01
          相关资源
          最近更新 更多