风格的Andr​​oid搜索查看降下来弹出 [英] Style Android SearchView Drop down popup

查看:98
本文介绍了风格的Andr​​oid搜索查看降下来弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何样式下拉了Android 4.0的弹出搜索查看

I would like to know how to style the drop down popup of the Android 4.0 SearchView ?

我使用了 Theme.Sherlock.Light.DarkActionBar ,但我不知道如何样式下拉搜索到一个白色背景和黑色文字?

I'm using the Theme.Sherlock.Light.DarkActionBar, but I don't know how to style the drop down search into a white background and a black text?

推荐答案

出于某种原因,主题化使用searchAutoCompleteTextView不工作对我来说无论是。因此,建立我的搜索查看时,我解决了它使用下面的code:

For some reason theming using the "searchAutoCompleteTextView" wasn't working for me either. So I solved it using the following code when setting up my SearchView:

请注意:这是所有做的是Android V7支持/ AppCompat库

Note: This is all done with the android v7 support/AppCompat library

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    // Theme the SearchView's AutoCompleteTextView drop down. For some reason this wasn't working in styles.xml
    SearchAutoComplete autoCompleteTextView = (SearchAutoComplete) searchView.findViewById(R.id.search_src_text);

    if (autoCompleteTextView != null) { 
        autoCompleteTextView.setDropDownBackgroundResource(R.drawable.abc_search_dropdown_light);
    }
}

有通过兼容性库提供了两个搜索下拉资源,它们是

There are two search drop down resources provided by the compatibility library, they are

  • R.drawable.abc_search_dropdown_light(背景光)
  • R.drawable.abc_search_dropdown_dark(暗背景)

这篇关于风格的Andr​​oid搜索查看降下来弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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