How to change searchview icon color?

后端 未结 9 1213
北海茫月
北海茫月 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 14:06

    I have found that in later (2020) appCompat scenarios I have had trouble changing icon colors, but found this one to work:

    (kotlin)

    
    searchItem.icon.colorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(Color.RED, BlendModeCompat.SRC_ATOP)
    
    
    0 讨论(0)
  • 2020-12-19 14:11
     final SearchView searchViewAndroidActionBar = (SearchView) MenuItemCompat.getActionView(searchViewItem);
            // change close icon color
            ImageView iconClose = (ImageView) searchViewAndroidActionBar.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
            iconClose.setColorFilter(getResources().getColor(R.color.grey));
           //change search icon color
            ImageView iconSearch = searchViewAndroidActionBar.findViewById(android.support.v7.appcompat.R.id.search_button);
            iconSearch.setColorFilter(getResources().getColor(R.color.grey));
    
    0 讨论(0)
  • 2020-12-19 14:11

    Use below code:

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView mSearchView = (SearchView) searchItem.getActionView();
    Drawable dr = searchItem.getIcon();
        
    dr.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_ATOP);
    

    OR:

    dr.setColorFilter(BlendModeColorFilterCompat
             .createBlendModeColorFilterCompat(Color.RED, BlendModeCompat.SRC_ATOP));
    
    0 讨论(0)
提交回复
热议问题