如何将光标背景设置为对EditText Android透明 [英] how to set cursor background transparent for EditText Android

查看:252
本文介绍了如何将光标背景设置为对EditText Android透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我触摸用于在Android上更改文本的EditText时遇到此问题:

I'm having this issue when I touch an EditText for changing text on Android:


白色框出现在红色光标周围,并且我需要使它透明以正确显示EditText的行.我该如何更改?


A white frame appears around the red cursor, and I need it to be transparent for showing properly the line of the EditText. How do I change this?

代码:

<EditText
            android:id="@+id/login_user_name_text"
            android:textCursorDrawable="@null"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="16sp"
            android:inputType="textEmailAddress"
            android:imeOptions="actionNext"
            android:maxLines="1"
            android:hint="@string/email"
            android:maxLength="60"
            />


编辑:我可以通过替换以下内容来解决此问题:


I could fix it by replacing:

<item name="android:background">@color/white</item>

<item name="android:background">@color/transparent</item>

在styles.xml中

in styles.xml

 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDisablePreview">true</item>
        <item name="android:background">@color/transparent</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    </style>

推荐答案

另一种解决方案,如果您在使用工具栏时在SearchView中遇到EditText 的问题,则该解决方案有效.

Another solution, which works if you are having this problem with an EditText inside a SearchView while using a Toolbar.

  1. 在您的活动XML中,将android:background="?attr/colorPrimary"属性添加到工具栏:

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ToolBarStyle"
android:background="?attr/colorPrimary"
android:elevation="2dp" />

  • 然后,从styles.xml中的ToolBarStyle中删除 <item name="android:background">@color/colorPrimary</item>.

  • Then, remove <item name="android:background">@color/colorPrimary</item> from your ToolBarStyle in styles.xml.

    希望这可以帮助其他人为这种情况寻找解决方案.

    Hope this helps someone else looking for a solution for this particular case.

    这篇关于如何将光标背景设置为对EditText Android透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆