How to change searchview icon color?

后端 未结 9 1291
北海茫月
北海茫月 2020-12-19 13:19

I know there\'s already a lot of answers for this question here, and I wouldn\'t be creating another thread if I hadn\'t already tried everything I saw here. Anyway, the qu

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 13:59

    For android.x,

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        ...
    
        ImageView searchIcon= 
        searchView.findViewById(androidx.appcompat.R.id.search_mag_icon);
    
        // To change color of close button, use:
        // ImageView searchCloseIcon = (ImageView)searchView
        //        .findViewById(androidx.appcompat.R.id.search_close_btn);
    
        searchIcon.setColorFilter(getResources().getColor(R.color.colorPrimary),
                android.graphics.PorterDuff.Mode.SRC_IN);
    
        ...
    
        return true;
    
    }
    

提交回复
热议问题