• 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"))
    }
  • 相关阅读:
    25个自适应菜单教程和脚本
    15+最好的视差滚动技术指南
    15个最好的视差滚动教程
    36个创意广告海报欣赏
    26个新鲜有魅力的自适应网站设计实例
    32+激发灵感的HTML5/CSS3网页设计教程
    15+ 易响应的CSS框架快速开启你的敏捷网站项目
    25个令人难忘的广告设计
    15个华丽的wordPress全屏商务主题
    30个精美的美元折纸艺术
  • 原文地址:https://www.cnblogs.com/qianyukun/p/6780603.html
Copyright © 2020-2023  润新知