SearchView自定義圖標以及文字大小顏色

話不多說,上代碼,有需要的同學可以直接拿去用,想要尋找爲什麼的請查看源碼。

public static void setIcon(SearchView seach, String hint, String text) {
        SearchView.SearchAutoComplete textView = (SearchView.SearchAutoComplete) seach.findViewById(R.id.search_src_text);
        textView.setTextColor(Color.WHITE);
        if (TextUtils.isEmpty(text)) {
            textView.setHint(hint);
        } else {
            textView.setText(text);
        }
        textView.setTextSize(14);
        textView.setHintTextColor(Color.WHITE);

        AppCompatImageView button = (AppCompatImageView) seach.findViewById(android.support.v7.appcompat.R.id.search_button);
        AppCompatImageView button1 = (AppCompatImageView) seach.findViewById(android.support.v7.appcompat.R.id.search_go_btn);
        AppCompatImageView button2 = (AppCompatImageView) seach.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
        button.setImageResource(R.mipmap.sousuo);
        button1.setImageResource(R.mipmap.sousuo2);
        button2.setImageResource(R.mipmap.shanchu);

        //        final int textSize = (int) (textView.getTextSize() * 1.25);
        //        Drawable mSearchHintIcon=getResources().getDrawable(R.mipmap.sousuo);
        //        mSearchHintIcon.setBounds(0, 0, textSize, textSize);
        //        final SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
        //        ssb.setSpan(new ImageSpan(mSearchHintIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //        ssb.append("請輸入搜索文字");
        //        textView.setHint(ssb);
    }

看了之後是不是覺得很簡單呢,對了,如果要將搜索框縮小爲圖標直接setIconified(false)就可以了。
要是有不明白的地方歡迎留言哈。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章