Change searchview action bar text color tooltip

How to change the color of the tooltip text in the search bar?

This question explains how to get EditText when using ABS: Android ActionBar Customize the look of the search

Is there an android.R.id file that I could use to get a link to EditText to change the color of the tooltip? Or is there another way to change the color?

Action bar search view hint text

+30
android search android-actionbar
Jul 22 '13 at 15:22
source share
18 answers

android: actionBarWidgetTheme of your main theme should point to a style that has android: textColorHint. This will allow you to change the color of the tooltip text in the search form.

+44
Jul 22 '13 at 15:29
source share
searchView.setQueryHint(Html.fromHtml("<font color = #ffffff>" + getResources().getString(R.string.hintSearchMess) + "</font>")); 
+42
Oct. 25 '13 at 18:51
source share
 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); 
+18
May 17 '14 at 18:48
source share

I decided to add this property to the main topic:

 <style name="AppTheme" parent="AppBaseTheme"> ..... ..... <item name="android:actionBarWidgetTheme">@style/MyActionBarWidgetTheme</item> </style> 

And then add the property that I want to change in this case, the color of the tooltip.

 <style name="MyActionBarWidgetTheme" parent="@android:style/Theme.Holo"> ..... ..... <item name="android:textColorHint">@color/blanco_60</item> </style> 

Hope this helps: D

+10
May 16 '14 at
source share

it 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

+8
Mar 13 '15 at 7:00
source share

The A SearchView extends from LinearLayout , so it contains other views. The trick is to find a view containing tooltip text and change the color programmatically. Going through the hierarchy of views, you can find a widget containing the help text:

 // get your SearchView with its id SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); // traverse the view to the widget containing the hint text LinearLayout ll = (LinearLayout)searchView.getChildAt(0); LinearLayout ll2 = (LinearLayout)ll.getChildAt(2); LinearLayout ll3 = (LinearLayout)ll2.getChildAt(1); SearchView.SearchAutoComplete autoComplete = (SearchView.SearchAutoComplete)ll3.getChildAt(0); // set the hint text color autoComplete.setHintTextColor(getResources().getColor(Color.WHITE)); 

This method works with any theme. In addition, you can change the appearance of other widgets in the SearchView hierarchy, such as EditText , which contains the search query.

+7
Mar 11 '14 at 4:05
source share

Here itโ€™s specific how you apply the style as above. The correct answer is to overload the style of the action panel widget using your own style. For a head light with a dark action bar, put this in your own stylesheet, for example res/values/styles_mytheme.xml :

 <style name="Theme.MyTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar"> <item name="android:actionBarWidgetTheme">@style/Theme.MyTheme.Widget</item> <!-- your other custom styles --> </style> <style name="Theme.MyTheme.Widget" parent="@android:style/Theme.Holo"> <item name="android:textColorHint">@android:color/white</item> <!-- your other custom widget styles --> </style> 

Make sure your application uses the theme theme as described in the enter link here

+6
Apr 20 '14 at 16:13
source share

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

 // 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); 
+4
Aug 25 '14 at 14:40
source share

Look at this class, it will help you solve your problem.

 import android.R.color; import android.content.Context; import android.graphics.Typeface; import android.widget.ImageView; import com.actionbarsherlock.widget.SearchView; import com.actionbarsherlock.widget.SearchView.SearchAutoComplete; public class MySearchView { public static SearchView getSearchView(Context context, String strHint) { SearchView searchView = new SearchView(context); searchView.setQueryHint(strHint); searchView.setFocusable(true); searchView.setFocusableInTouchMode(true); searchView.requestFocus(); searchView.requestFocusFromTouch(); ImageView searchBtn = (ImageView) searchView.findViewById(R.id.abs__search_button); searchBtn.setImageResource(R.drawable.ic_menu_search); // ImageView searchBtnClose = (ImageView) searchView.findViewById(R.id.abs__search_close_btn); // searchBtnClose.setImageResource(R.drawable.ic_cancel_search_bar); SearchAutoComplete searchText = (SearchAutoComplete) searchView.findViewById(R.id.abs__search_src_text); setFont(context, searchText); searchText.setTextColor(context.getResources().getColor(color.white)); searchText.setHintTextColor(context.getResources().getColor(color.white)); return searchView; } private static void setFont(Context _context, SearchAutoComplete searchText) { Typeface tf = null; Typeface currentType = searchText.getTypeface(); if (currentType == null) { tf = MyApplication.fontNormal; } else { int currentStyle = currentType.getStyle(); if (currentStyle == Typeface.BOLD) { tf = MyApplication.fontBold; } else if (currentStyle == Typeface.BOLD_ITALIC) { tf = MyApplication.fontBoldItalic; } else if (currentStyle == Typeface.ITALIC) { tf = MyApplication.fontItalic; } else { tf = MyApplication.fontNormal; } } searchText.setTypeface(tf); } public static SearchView getSearchView(Context context, int strHintRes) { return getSearchView(context, context.getString(strHintRes)); } } 
+3
03 Oct '13 at 17:56
source share

If you want to change the left arrow button in the search box, add the application: collapseIcon.

 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/colorPrimary" app:collapseIcon="@drawable/ic_search_view_home" /> 

If you want to change the text color and text color, add the following.

 EditText searchEditText = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); searchEditText.setTextColor(Color.WHITE); searchEditText.setHintTextColor(Color.WHITE); 

If you want to change the close icon, add the following.

 ImageView imvClose = searchView.findViewById(android.support.v7.appcompat.R.id .search_close_btn); imvClose.setImageResource(R.drawable.ic_search_view_close); 
+2
Dec 19 '17 at 17:07 on
source share

You can also configure SearchView to your menu item manually and thereby fully control the presentation.

+1
Jul 22 '13 at 15:58
source share
 int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); TextView textView = (TextView) searchView.findViewById(id); textView.setTextColor(Color.WHITE); textView.setHintTextColor(Color.WHITE); 
+1
May 17 '14 at 19:53
source share

With this you can change the search xml

  • Text search text color
  • Text search
  • Search close icon
  • Search Hint Icon
  • Search bar
 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 the pullable / search _plate.xml

 <!-- main color --> <item android:bottom="1dp" android:left="1dp" android:right="1dp"> <shape > <solid android:color="@color/app_theme_color" /> </shape> </item> <!-- draw another block to cut-off the left and right bars --> <item android:bottom="10.0dp"> <shape > <solid android:color="@color/app_theme_color" /> </shape> </item> </layer-list> 
+1
01 Sep '15 at 10:48
source share

Try this code. It is very easy.

  // Associate searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); searchEditText.setHint("Search"); searchEditText.setHintTextColor(getResources().getColor(R.color.white)); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 

searchEditText.setHintTextColor (. GetResources () GetColor (R.color.white));

+1
May 13 '16 at 10:13
source share

The solution to change the color of the text of the search hint in the search form:

  SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); searchAutoComplete.setHintTextColor(Color.GRAY); 
+1
Jun 06 '16 at 5:40
source share

This is very easy to achieve with styles.xml Just understand that the SearchView theme is directly related to the toolbar theme from which menu.xml is selected as app:actionViewClass .

  • Create a toolbar style.
  • Apply this style as a theme in the toolbar and it changes all the related views and their properties.
+1
May 09 '17 at 11:23
source share

With the latest appcompat library (or if you are targeting 5.0+), this can be done purely in XML using ThemeOverlay :

 <style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar"> <item name="autoCompleteTextViewStyle">@style/Widget.MyApp.AutoCompleteTextView.SearchView</item> </style> <style name="Widget.MyApp.AutoCompleteTextView.SearchView" parent="Widget.AppCompat.AutoCompleteTextView"> <item name="android:textColor">#000</item> <item name="android:textColorHint">#5000</item> </style> 

And then in your layout file:

 <android.support.v7.widget.Toolbar app:theme="@style/ThemeOverlay.MyApp.ActionBar" ... /> 

If you also want it to apply to actions using an ActionBar instead of a Toolbar , you can add this to the Activity theme:

 <style name="Theme.MyApp" parent="Theme.AppCompat"> <item name="actionBarTheme">@style/ThemeOverlay.MyApp.ActionBar</item> ... </style> 
0
Mar 22 '16 at 18:59
source share

Put this in your xml file:

 android:textColorHint="@android:color/white" 
-one
Mar 10 '14 at 10:40
source share



All Articles