微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 如何更改工具栏SearchView下划线颜色为灰色

我在扩展搜索栏时尝试更改搜索视图的下划线颜色

    SearchView.SearchAutoComplete autoCompleteTextView = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);
    autoCompleteTextView.setCursorVisible(true);
    autoCompleteTextView.setTextColor(ContextCompat.getColor(this, R.color.textcolor_light_gray));
    autoCompleteTextView.setHintTextColor(autoCompleteTextView.getTextColors().withAlpha(255));
    autoCompleteTextView.setTextSize(16);

    View searchplate = (View)searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    searchplate.setBackgroundResource(R.drawable.autocomplete_bg);

在这里我用主题来改变颜色

 <style name="MySearchViewStyle" parent="Widget.AppCompat.Light.SearchView">
    <!-- Background for the search query section (e.g. EditText) -->
    <item name="queryBackground">@color/darkgray</item>

</style>

但没有什么对我有用.任何人帮我…

解决方法:

最后我得到了解决方案..

    View searchplate = (View)searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    searchplate.getBackground().setColorFilter(Color.DKGRAY, PorterDuff.Mode.MULTIPLY);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐