问题
I'm having this issue when I touch an EditText for changing text on Android:
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?
code:
<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"
/>
EDIT: I could fix it by replacing:
<item name="android:background">@color/white</item>
for
<item name="android:background">@color/transparent</item>
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>
回答1:
Sorry for the late,
I think you have <item name="android:popupBackground">@color/white</item> in your style from v21,
just remove it, It may solve your problem
回答2:
better using @android:color/transparent instead of null on the android:textCursorDrawable="@android:color/transparent"
回答3:
Add the following to your EditText XML instead of null;
android:textCursorDrawable="@drawable/colorcursor"
Then, create a file called colorcursor.xml inside your drawable folder;
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:width="3dp" />
<solid android:color="#FFFFFF" />
</shape>
回答4:
Setting android:background to transparent didn't do the trick for me.
In my case I set a theme to the parent viewgroup that defined the background to be a certain color, so it was applied to the EditText as well. Making sure that the background was just set for the parent solved it.
回答5:
Another solution, which works if you are having this problem with an EditText inside a SearchView while using a Toolbar.
In your activity XML add the
android:background="?attr/colorPrimary"attribute to Toolbar:<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" />Then, remove
<item name="android:background">@color/colorPrimary</item>from yourToolBarStylein styles.xml.
Hope this helps someone else looking for a solution for this particular case.
来源:https://stackoverflow.com/questions/41232652/how-to-set-cursor-background-transparent-for-edittext-android