Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set SearchView TextSize?

I have a SearchView inside a LinearLayout and I'm trying to set a different TextSize for it (the SearchView) but when setting android:textSize="60sp" for example, nothing happens.

This is my code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"           android:layout_width="fill_parent"           android:layout_height="wrap_content"           android:orientation="vertical"           android:padding="2dp"> <SearchView         android:id="@+id/searchView"         android:layout_width="350dp"         android:textSize="60sp"         android:layout_height="80dp"         android:layout_marginTop="15dp"/> <ListView         android:id="@+id/search_results"         android:layout_width="fill_parent"         android:layout_height="wrap_content"/> 

Does anyone know how to modify the TextSize of the control?

like image 942
tetius Avatar asked May 10 '12 13:05

tetius


2 Answers

You can achieve this using a theme:

in styles.xml

<style name="AppSearchView" parent="Widget.AppCompat.SearchView" >         <item name="android:textSize">60sp</item>     </style> 

And using a SearchView

<android.support.v7.widget.SearchView             android:id="@+id/searchView"             android:layout_width="350dp"             app:theme="@style/AppSearchView"             android:layout_height="80dp"             android:layout_marginTop="15dp"/> 
like image 165
Filippe Carvalho Avatar answered Sep 17 '22 13:09

Filippe Carvalho


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, getResources().getDimensionPixelSize(R.dimen.text_small)); 
like image 38
Pongpat Avatar answered Sep 17 '22 13:09

Pongpat