其他分享
首页 > 其他分享> > android – 如何更改工具栏SearchView下划线颜色为灰色

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

标签:android,android-toolbar,xml,toolbar,searchview
来源: https://codeday.me/bug/20190727/1553865.html