Changing action bar searchview hint text color

后端 未结 18 1367
时光说笑
时光说笑 2020-12-12 21:47

How can I change the action bar search view hint text colour?

This question explains how to get the EditText when using ABS: Android ActionBar Customize Search View

18条回答
  •  独厮守ぢ
    2020-12-12 22:33

    By using this you can change the Searchable xml

    1. Search text hint color
    2. Search Text
    3. Search close icon
    4. Search hint icon
    5. Search plate
    int searchHintBtnId = searchView.getContext().getResources()
                        .getIdentifier("android:id/search_mag_icon", null, null);
         int hintTextId = searchView.getContext()
                        .getResources()
                        .getIdentifier("android:id/search_src_text", null, null);
                int closeBtnId = searchView.getContext()
                        .getResources()
                        .getIdentifier("android:id/search_close_btn", null, null);
                // Set the search plate color to white
                int searchPlateId = getResources().getIdentifier("android:id/search_plate", null, null);
    
                View view = searchView.findViewById(searchPlateId);
                view.setBackgroundResource(R.drawable.search_plate);
    
                ImageView closeIcon = (ImageView) searchView.findViewById(closeBtnId);
                closeIcon.setImageResource(R.drawable.close);
    
                ImageView searchHintIcon = (ImageView) searchView.findViewById(searchHintBtnId);
                searchHintIcon.setImageResource(R.drawable.search);
    
                TextView textView = (TextView) searchView.findViewById(hintTextId);
                textView.setTextColor(getResources().getColor(R.color.search_text_color));
                textView.setHintTextColor(getResources().getColor(R.color.search_hint_text_color));
    

    Here is drawable/search_plate.xml

    
    
        
            
        
    
    
    
    
        
            
        
     
    

提交回复
热议问题