工具栏搜索建议主题化 [英] Toolbar Search Suggestions Theming

查看:306
本文介绍了工具栏搜索建议主题化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图改变搜索建议轻题材。
我使用的应用程序兼容性-V7:22.2.0图书馆和阅读有关新功能搜索视图控件(android.support.v7.widget.SearchView)。

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).

第一次尝试栏目

工具栏

<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" />

主题曲

<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>

搜索查看主题

<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.

第二次尝试栏目

第二次尝试是覆盖在工具栏覆盖的主题:

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

叠加主题

<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:

建议行布局

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

我认为我远来完成这个...你能帮助我吗?

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

推荐答案

建议是系统创建一个动态列表,而不是一个活动。所以,你可以轻主题并不适用于它。

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.

使用 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" />

和应用该样式

<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>

现在我得到这个

光的建议

您可以根据您的需要给予更多的风格。

You can give more style according to your need

这篇关于工具栏搜索建议主题化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆