使用支持库更改操作栏中搜索提示的文本颜色 [英] Change text color of search hint in actionbar using support library

查看:28
本文介绍了使用支持库更改操作栏中搜索提示的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改搜索视图提示的文本颜色,但我尝试了很多方法都没有成功.就像在这篇文章中一样:更改操作栏搜索视图提示文本颜色

I want to change the text color of search view hint, but I tried in many ways with no success. Like in this post: Changing action bar searchview hint text color

我正在使用 Appcompat,操作栏的支持库.

I'm using Appcompat, support library of actionbar.

我用空指针返回尝试了这个:

I tried this with null pointer return:

AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources().getColor(R.color.white));
searchText.setTextColor(getResources().getColor(R.color.white)); 

推荐答案

我猜是 AutoCompleteTextView 的 id 错误.除非您使用自定义操作栏搜索小部件.试试看.像下面这样:

Wrong id for the AutoCompleteTextView, I guess. Unless you use a custom Action Bar Search widget. Try smth. like the following:

((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text))
            .setHintTextColor(getResources().getColor(R.color.white));

这篇关于使用支持库更改操作栏中搜索提示的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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