1

I have tried these approaches which did not work -

Approach 1:

    val searchView = binding.mSearchView
    val linearLayout1 = searchView.getChildAt(0) as LinearLayout
    val linearLayout2 = linearLayout1.getChildAt(2) as LinearLayout
    val linearLayout3 = linearLayout2.getChildAt(1) as LinearLayout
    val autoComplete = linearLayout3.getChildAt(0) as AutoCompleteTextView
    autoComplete.textSize = 12f

Approach 2:

    <string name="search_hint"><font size="12">My hint string</font></string>   
 
    val searchSrcTextId = resources.getIdentifier("android:id/search_src_text", null, 
    null)
    val searchEditText = binding.mSearchView.findViewById<View>(searchSrcTextId) as 
    EditText
    searchEditText.hint = getString(R.string.search_hint)

This gives Null Pointer exception on line 3.

Approach 3:

<string name="search_hint"><font size="12">My hint string</font></string>

binding.mSearchView.queryHint = getString(R.string.search_hint)
Or
binding.mSearchView.queryHint = getText(R.string.search_hint)

Approach 4:

binding.mSearchView.queryHint = Html.fromHtml("<small><small> 
<small>"+getString(R.string.hint)
+ "</small></small></small>")

I want to change queryHint text size to 12sp of my androidx.appcompat.widget.SearchView.

Please help, i have tried everything i could, but not able to do it. Thanks in advance! :)

User7788
  • 31
  • 2
  • 1
    Hint will take the same text size as text . So you have few options here Use Spannable as Hint with RelativeSizeSpan or you can handle the text Size inside text Change listener. Something [Like this](https://stackoverflow.com/questions/39107032/how-to-change-hint-text-size-without-changing-the-text-size-in-edittext). – ADM Feb 04 '22 at 04:53

1 Answers1

0

Refer this link How to set SearchView TextSize?

You could do these using code

SearchView searchView = new SearchView(context);
LinearLayout linearLayout1 = (LinearLayout) searchView.getChildAt(0);
LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
autoComplete.setTextSize(60);

Here is another solution

SearchView searchView = new SearchView(context);
AutoCompleteTextView search_text = (AutoCompleteTextView) searchView.findViewById(searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null));
search_text.setTextColor(Color.WHITE);
search_text.setTextSize(TypedValue.COMPLEX_UNIT_PX, search_text.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.text_small));
Siddarth Jain
  • 304
  • 1
  • 6