更改appcompat的搜索查看文本和提示颜色 [英] Change appcompat's SearchView text and hint color

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

问题描述

是否有人知道如何改变appcompat搜索查看的文本颜色?我花了2小时,试图从这么几个建议,没有工作。

下面是我的code:

 <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:espacios =htt​​p://schemas.android.com/apk/res-auto>

    <项目
        机器人:ID =@ + ID / layer_switcher_button
        机器人:图标=@可绘制/ b_categorias
        机器人:标题=@字符串/ menu_layer_switcher_title
        espacios:showAsAction =ifRoom | collapseActionView/>
    <项目
        机器人:ID =@ + ID / ACTION_SEARCH
        机器人:图标=@可绘制/ b_buscar
        机器人:标题=@字符串/ menu_search_title
        espacios:actionViewClass =android.support.v7.widget.SearchView
        espacios:showAsAction =ifRoom | collapseActionView/>

< /菜单>
 

和我的活动我有这样的:

 公共布尔onCreateOptionsMenu(功能菜单){
    。getMenuInflater()膨胀(R.menu.main,菜单);

    菜单项layerSwitcher = menu.findItem(R.id.layer_switcher_button);
    layerSwitcher.setOnMenuItemClickListener(新OnMenuItemClickListener(){

        @覆盖
        公共布尔onMenuItemClick(菜单项项){
        onLayerSwitcherButtonClicked();
            返回false;
        }
    });

    菜单项searchItem = menu.findItem(R.id.action_search);
    搜索查看搜索查看=(搜索查看)MenuItemCompat.getActionView(searchItem);

    的LinearLayout LL =(的LinearLayout)searchView.getChildAt(0);
    TextView中的TextView =(TextView中)ll.getChildAt(0);

    textView.setTextColor(R.color.white);
}
 

解决方案

 搜索查看搜索查看=新的搜索查看(的getContext());
SearchView.SearchAutoComplete theTextArea =(SearchView.SearchAutoComplete)searchView.findViewById(R.id.search_src_text);
theTextArea.setTextColor(Color.WHITE); //或任何你想要的颜色
 

Does anybody know how to change the text color of the appcompat SearchView? I've spent 2 hours and tried several suggestions from SO and none works.

Here is my code:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:espacios="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/layer_switcher_button"
        android:icon="@drawable/b_categorias"
        android:title="@string/menu_layer_switcher_title"
        espacios:showAsAction="ifRoom|collapseActionView"/>
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/b_buscar"
        android:title="@string/menu_search_title"
        espacios:actionViewClass="android.support.v7.widget.SearchView"
        espacios:showAsAction="ifRoom|collapseActionView"/>

</menu>

And in my activity I have this:

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);

    menuItem layerSwitcher = menu.findItem(R.id.layer_switcher_button);
    layerSwitcher.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
        onLayerSwitcherButtonClicked();
            return false;
        }
    });

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    LinearLayout ll = (LinearLayout) searchView.getChildAt(0);
    TextView textView = (TextView) ll.getChildAt(0);

    textView.setTextColor(R.color.white);
}

解决方案

SearchView searchView = new SearchView(getContext());
SearchView.SearchAutoComplete theTextArea = (SearchView.SearchAutoComplete)searchView.findViewById(R.id.search_src_text);
theTextArea.setTextColor(Color.WHITE);//or any color that you want

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

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