Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar Search Suggestions Theming

I’m trying to change search suggestions to “light theme”. I’m using appcompat-v7:22.2.0 library and read about new feature for customizing search view widget (android.support.v7.widget.SearchView).

FIRST TRY SECTION

Toolbar

<android.support.v7.widget.Toolbar 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:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

Main Theme

<style name="Main.Theme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/red</item>
    <item name="colorPrimaryDark">@color/red_dark</item>
    <item name="searchViewStyle">@style/Main.Theme.SearchView</item>
</style>

SearchView Theme

<style name="Main.Theme.SearchView" parent="Widget.AppCompat.Light.SearchView">
    <item name="voiceIcon">@mipmap/test_icon</item>
</style>

This way I'm not able to affect the search view. To test it I'm changing the voice icon in the search view, and it doesn't change from default.

SECOND TRY SECTION

The second try was to override the overlay theme in toolbar:

Overlay Theme

<style name="Main.Theme.Overlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="searchViewStyle">@style/Main.Theme.SearchView</item>
</style>

This way I've some feedback, but I lose "material design", in particular I've the "old" hint icon and it's underlined. My final aim is to change the search suggestion row background:

Suggestion row layout

<item name="suggestionRowLayout">@layout/my_custom_layout</item>

I think that I'm far away to accomplish this...can you help me?

like image 205
Jumpa Avatar asked Jun 12 '15 16:06

Jumpa


1 Answers

Suggestions is a dynamic list created by system and is not an activity. So you cannot apply light theme to it.

Instead you can customize suggestions to give it feel like a light theme by using style.

use this hint_row.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="@style/suggestionsTheme"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:gravity="center_vertical"
    android:text="demo"
    android:paddingLeft="15dp"
    android:paddingRight="15dp" />

And apply this style

<style name="suggestionsTheme" parent="TextAppearance.AppCompat.Light.SearchResult.Subtitle" >
        <item name="android:background">@android:color/white</item>
        <item name="android:textColor">@android:color/black</item>

Now I am getting this

Light suggestions

You can give more style according to your need

like image 112
Azim Ansari Avatar answered Oct 18 '22 06:10

Azim Ansari