Denis Steinman
Denis Steinman

Reputation: 7809

Can't change the style of the SearchView suggestions in Android

I need to change the SearchView suggestions style to the AppCompat.Light theme (i.e. gray text on a white background). But I retried a lot of variants and no one changed the SearchView suggestions style.
Screenshot

My layout:

<android.support.design.widget.AppBarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:theme="@style/Widget.AppTheme.Toolbar"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

Styles:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
    </style>

    <style name="AppTheme.NoActionBarTrans">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="Widget.AppTheme.Toolbar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse"/>

</resources>

The app theme is AppTheme, the activity theme is AppTheme.NoActionBarTrans. What am I doing wrong? I tried to declare SearchView style but it just ignores this style.

Upvotes: 0

Views: 1044

Answers (1)

H Raval
H Raval

Reputation: 1903

you can style dropdown programatically using this code

SearchView searchView = new SearchView(context);
LinearLayout linearLayout1 = (LinearLayout) searchView.getChildAt(0);
LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
//Set the input text color
autoComplete.setTextColor(Color.WHITE);
// set the hint text color
autoComplete.setHintTextColor(Color.WHITE);
//Some drawable (e.g. from xml)
autoComplete.setDropDownBackgroundResource(R.drawable.drop_down_bg);

Upvotes: 2

Related Questions