<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right|end">
<android.support.v7.widget.SearchView
android:background="@null"
android:id="@+id/searchView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
my colorAccent is also colorPrimary, how to change cursor color, I referred other quetions, but nothing solved my problem
You have two options.
1). You can make use of these attributes in your styles.xml
for changing the cursor color.
<item name="colorControlNormal">@color/colorEditextDisabled</item>
<item name="colorControlActivated">@color/colorEditextEnabled</item> // change this color to the required cursor color your need.
<item name="colorControlHighlight">@color/colorEditextEnabled</item>
2). Find the EditText from your SearchView
and set the android:textCursorDrawable
attribute to @null
. This will result in android:textColor
as the cursor color. But as you can't set textCursorDrawable
programatically, so you have to make use of reflection in this case.
EditText etSearch= ((EditText) yourSearchView.findViewById(android.support.v7.appcompat.R.id.search_src_text));
try {
Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
f.setAccessible(true);
f.set(etSearch, null);// set textCursorDrawable to null
} catch (Exception e) {
e.printStackTrace();
}
etSearch.setTextColor(ContextCompat.getColor(mContext, R.color.yourColor));
Hopefully, any of the solutions above will work for you..!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With