MaterialSearchBar
MaterialSearchBar copied to clipboard
Unable to change cursor color
I have tried to change the cursor color with a custom theme, but it's always white. Any suggestions ?
I have the same issue
E/ContentValues: init:
com.mancj.materialsearchbar.EditTextStyleHelper$EditTextStyleChangeError: Error applying changes to androidx.appcompat.widget.AppCompatEditText{355d4fb VFED..CL. ......I. 0,0-0,0 #7f0a0655 app:id/mt_editText}
at com.mancj.materialsearchbar.EditTextStyleHelper.apply(EditTextStyleHelper.java:125)
at com.mancj.materialsearchbar.EditTextStyleHelper.applyChanges(EditTextStyleHelper.java:40)
at com.mancj.materialsearchbar.MaterialSearchBar.setupSearchEditText(MaterialSearchBar.java:314)
at com.mancj.materialsearchbar.MaterialSearchBar.postSetup(MaterialSearchBar.java:278)
at com.mancj.materialsearchbar.MaterialSearchBar.init(MaterialSearchBar.java:220)
at com.mancj.materialsearchbar.MaterialSearchBar.<init>(MaterialSearchBar.java:123)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
/**
* Setup editText coloring and drawables
*/
private void setupSearchEditText() {
try {
EditTextStyleHelper.applyChanges(this.searchEdit, this.textCursorColor, this.leftTextSelectorTint, this.rightTextSelectorTint, this.middleTextSelectorTint,
this.leftTextSelectorRes, this.rightTextSelectorRes, this.middleTextSelectorRes, this.textSelectorTintEnabled);
} catch (EditTextStyleHelper.EditTextStyleChangeError e) {
Log.e(TAG, "init: ", e);
}
......
I guess the problem is here.
I have the same problem, too. mt_textCursorTint
does not change the color, and it's alway white.
also meet this problem,how to resolve
I managed to change via code
private var editText: EditText? = null
editText = etSearch.findViewById(R.id.mt_editText)
try { val f = TextView::class.java.getDeclaredField("mCursorDrawableRes") f.isAccessible = true f.set(editText, R.drawable.home_search_cursor); } catch (e: Exception) { }
home_search_cursor.xml
Fix for the issue! Create a xml file in drawable folders called color_cursor.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ff000000" />
<size android:width="1dp" />
change the color in xml to whatever color you want for the cursor.