如何更改ActionBarSherlock中具有深色背景的搜索视图的自动填充文本颜色? [英] How to change the autocomplete text color for search view inside of ActionBarSherlock with dark background?

查看:383
本文介绍了如何更改ActionBarSherlock中具有深色背景的搜索视图的自动填充文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有基于 Theme.Sherlock.Light.DarkActionBar 的ActionBarSherlock的自己的主题,这里是我的样式:

I have my own theme for ActionBarSherlock based on Theme.Sherlock.Light.DarkActionBar, here are my styles:

<style name="Theme.MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
</style>

<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/action_bar</item>
    <item name="background">@drawable/action_bar</item>
</style>

其中 @ drawable / action_bar

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/color_action_bar_bottom_line" />
        </shape>
    </item>

    <item android:bottom="2dp">
        <shape android:shape="rectangle">
            <solid android:color="@color/color_action_bar_background" />
        </shape>
    </item>
</layer-list>

一切看起来都很棒,除了一件事情:SearchView中的文本(当我在ActionBar中使用搜索模式)是黑暗的黑暗,所以我看不到任何东西。我尝试手动设置SearchView的文本颜色:

Everything looks great except one thing: the text in the SearchView (when I use the search mode in ActionBar) is "dark on dark", so I cannot see anything. I tried to set the text colors for SearchView manually:

AutoCompleteTextView searchTextView =
        (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchTextView.setTextColor(Color.WHITE);
searchTextView.setHintTextColor(Color.LTGRAY);
searchTextView.setHighlightColor(Color.WHITE);
searchTextView.setLinkTextColor(Color.WHITE);

这帮助了很多,但我不能改变自动填充文字的颜色:

This helped a lot but I cannot change the color of autocomplete text:

>

如你所见,它仍然是黑色的。

As you see, it's still black. How can I set the white text color for this kind of text?

推荐答案

我通过禁用自动完成功能解决了这个问题禁用,如果您将编辑类型设置为可见密码),但这个解决方案不是很好,我仍在寻找更好的一个。

I solved this by disabling autocomplete feature (it will be disabled if you'll set the edit type to Visible Password), but this solution is not very good and I'm still in search for better one.

private SearchView getSearchView() {
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
    searchView.setQueryHint("Search for items");
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    AutoCompleteTextView searchTextView =
            (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
    if (searchTextView != null) {
        searchTextView.setInputType(InputType.TYPE_CLASS_TEXT
                                    | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
        searchTextView.setTypeface(Typeface.DEFAULT);
    }
    return searchView;
}

这篇关于如何更改ActionBarSherlock中具有深色背景的搜索视图的自动填充文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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