Is it possible to change the textcolor on an Android SearchView?

The SearchView element doesn't have any properties for changing the text color. The default text color is black and doesn't work on our dark background. Is there a way to change the color of the text without resorting to hacks?

I found this similar question related to changing the text size, but so far, it doesn't have any answers: How to set SearchView TextSize?


尝试这样:你可以从sdk得到textview的句柄,然后改变它,因为它们不公开地公开。

int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView textView = (TextView) searchView.findViewById(id);
textView.setTextColor(Color.WHITE);

Add

<item name="android:editTextColor">@android:color/white</item>

to the parent theme and that should change the entered text. You can also use

<item name="android:textColorHint">@android:color/white</item>

to change the hint text for the SearchView. (Note that you can replace the @android:color/white with whatever appropriate value you're hoping to use)


这对我有用。

SearchView searchView = (SearchView) findViewById(R.id.search);
EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchEditText.setTextColor(getResources().getColor(R.color.white));
searchEditText.setHintTextColor(getResources().getColor(R.color.white));
链接地址: http://www.djcxy.com/p/92940.html

上一篇: 如何更改android的SearchView文本

下一篇: 是否可以更改Android SearchView上的文字颜色?