android - 如何在深色背景的 ActionBarSherlock 中更改搜索 View 的自动完成文本颜色?

标签 android colors actionbarsherlock android-theme autocompletetextview

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

<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 是一个 xml:

<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 的文本颜色:

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

这很有帮助,但我无法更改自动完成文本的颜色:

enter image description here

如您所见,它仍然是黑色的。如何为这种文本设置白色文本颜色?

最佳答案

试试这段代码

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);
autoComplete.setTextColor(Color.WHITE);

SearchView searchView = new SearchView(context);
AutoCompleteTextView search_text = (AutoCompleteTextView) searchView.findViewById(searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null));
search_text.setTextColor(Color.WHITE);

这是我自己在这里的回答How to set SearchView TextSize?

关于android - 如何在深色背景的 ActionBarSherlock 中更改搜索 View 的自动完成文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15008711/

相关文章:

java - Android java将2d数组分配给3d数组

android - Cocos2d-js:一些演示不能在 Genymotion 上运行

安卓操作栏 : Changing the color of Action Buttons

android - 如何将 ActionMode 完成按钮对齐到 ActionBar 的右侧而不是左侧?

Android Studio Pre Dexing 失败

java - 无法在 Android 项目中使用 Eclipse 的剪贴簿

android - 当应用程序在后台时,ViewPager fragment 被破坏?

javascript - 使用javascript计算颜色值(r,g,b)

go - 如何从 RGB 颜色中获取十六进制颜色?

excel - 更改条形图中的条形颜色