• searchView 颜色 icon 设置


    public void initSearchViewActions() {
    searchView.setMaxWidth(Integer.MAX_VALUE);
    searchView.onActionViewExpanded();
    searchView.setQueryHint(getString(R.string.search_tips));
    searchView.setOnQueryTextListener(this);
    searchView.setSubmitButtonEnabled(true);
    try {
    Field field = searchView.getClass().getDeclaredField("mGoButton");
    field.setAccessible(true);
    ImageView mGoButton = (ImageView) field.get(searchView);
    mGoButton.setImageResource(R.mipmap.ic_menu_search);

    Field fieldSearch = searchView.getClass().getDeclaredField("mSearchButton");
    fieldSearch.setAccessible(true);
    ImageView mSearchButton = (ImageView) field.get(searchView);
    mSearchButton.setVisibility(View.GONE);

    Field fieldClear = searchView.getClass().getDeclaredField("mCloseButton");
    fieldClear.setAccessible(true);
    ImageView mCloseButton = (ImageView) fieldClear.get(searchView);
    mCloseButton.setImageResource(R.mipmap.ic_menu_clear);

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

    Field ownField = searchView.getClass().getDeclaredField("mSearchPlate"); // 注意mSearchPlate的背景是stateListDrawable(不同状态不同的图片)
    // 所以不能用BitmapDrawable
    // setAccessible 它是用来设置是否有权限访问反射类中的私有属性的,只有设置为true时才可以访问,默认为false
    ownField.setAccessible(true);
    View mView = (View) ownField.get(searchView);
    mView.setBackgroundColor(Color.TRANSPARENT);
    } catch (Exception e) {
    LogUtil.e(e.getMessage(), e);
    }

    int completeViewId = searchView.getResources().getIdentifier("android:id/search_src_text",null,null);
    mAutoCompleteTextView = (AutoCompleteTextView) searchView.findViewById(completeViewId);
    mAutoCompleteTextView.setThreshold(0);
    mAutoCompleteTextView.setTextColor(Color.parseColor("#ffffff"));
    mAutoCompleteTextView.setHintTextColor(Color.parseColor("#ffffff"))
    }
  • 相关阅读:
    Rest Project Performace Pressure Test
    Tomcat APR & Linux Optimization
    关于启用 HTTPS 的一些经验分享(二)
    关于启用 HTTPS 的一些经验分享(一)
    JVM垃圾回收机制总结:调优方法
    LVS+Keepalived搭建高可用负载均衡
    LVS搭建负载均衡(二)DR模型
    LVS搭建负载均衡(一)NAT模型
    编译安装Nginx和PHP(带编译mysql)
    centos7下利用httpd2.4配置svn并使用Ldap用户认证
  • 原文地址:https://www.cnblogs.com/qianyukun/p/6780603.html
Copyright © 2020-2023  润新知