zoukankan      html  css  js  c++  java
  • 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"))
    }
  • 相关阅读:
    1.时间复杂度与空间复杂度分析
    数据结构与算法之重头再来
    MySQL时间字段与业务代码取出的时间不一致问题
    [redtiger]在线靶场level3
    win10 卡顿 MsMpEng.exe进程
    react 笔记 局部打印 print
    react table td 自动换行
    kali apt-get update release文件过期
    ubuntu怎么切换到root用户,切换到root账号方法
    winscp连接kali 使用预置密码验证 拒绝访问
  • 原文地址:https://www.cnblogs.com/qianyukun/p/6780603.html
Copyright © 2011-2022 走看看