Changing action bar searchview hint text color

后端 未结 18 1412
时光说笑
时光说笑 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:29

    Just get the textView id of search widget and use setTextColor() method to change the search text color and setHintTextColor() to change the search hints text color.

    // Get textview id of search widget
    int id =  searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
    TextView textView = (TextView) searchView.findViewById(id);
    
    // Set search text color
    textView.setTextColor(Color.WHITE);
    
    // Set search hints color
    textView.setHintTextColor(Color.GRAY);
    

提交回复
热议问题