Changing action bar searchview hint text color

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

    this worked for me :-)

     EditText seartext = searchView.findViewById(R.id.search_src_text);
        seartext.setTextColor(Color.WHITE);
        seartext.setHintTextColor(Color.GRAY);
    
    0 讨论(0)
  • 2020-12-12 22:24

    android:actionBarWidgetTheme of your main theme should point to a style that has a android:textColorHint in it. That one will allow changing the hint text color of the search view.

    0 讨论(0)
  • 2020-12-12 22:25

    This is really simple to achieve using the styles.xml Just understand that themeing the SearchView is directly related to the theme of the Toolbar from whose menu.xml it is fetched as a app:actionViewClass.

    1. Create a style for Toolbar.
    2. Apply that style as theme on the Toolbar and it changes al the related views and their properties.
    0 讨论(0)
  • 2020-12-12 22:29
    SearchView searchView= (SearchView) findViewById(R.id.searchView1);
    int id = searchView.getContext()
                       .getResources()
                       .getIdentifier("android:id/search_src_text", null, null);
    TextView textView = (TextView) searchView.findViewById(id);
    textView.setTextColor(Color.WHITE);
    
    0 讨论(0)
  • 2020-12-12 22:29

    this worked for me, hope it helps

    ((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(getResources().getColor(R.color.white));
    

    also see this

    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题