Android Search Search Course Does Not Display As Single Toolbar Color

    <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 the cursor color, I pointed out other quetions, but nothing solved my problem.

+4
source share
2 answers

You have two options.

1). You can use these attributes in styles.xmlto change the color of the cursor.

<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 yours SearchViewand set the attribute android:textCursorDrawablevalue @null. This will result android:textColorin the color of the cursor. But since you cannot install textCursorDrawableprogrammatically, so you need to use 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));

, ..!!

+10

colorAccent style.xml...

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/orange</item>
    <item name="colorPrimaryDark">@color/dark_orange</item>
    <item name="colorAccent">@color/blue</item>
</style>
+3

Source: https://habr.com/ru/post/1626903/


All Articles