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, getResources().getDimensionPixelSize(R.dimen.text_small));
Change SearchView TextSize
try this one
you have to pass your SearchView
and textSize
in this method
private void setSearchviewTextSize(SearchView searchView, int fontSize) {
try {
AutoCompleteTextView autoCompleteTextViewSearch = (AutoCompleteTextView) searchView.findViewById(searchView.getContext().getResources().getIdentifier("app:id/search_src_text", null, null));
if (autoCompleteTextViewSearch != null) {
autoCompleteTextViewSearch.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
} else {
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(TypedValue.COMPLEX_UNIT_SP, fontSize);
}
} catch (Exception e) {
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(TypedValue.COMPLEX_UNIT_SP, fontSize);
}
}
update your XML also
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"/>
</LinearLayout>
How to change text size in places autocompletefragment in android?
Using fragment instance you can change the font size and whatever you want with the Search box EditText
.. this is how you need to do
// placeAutocompleteFragment - is my PlaceAutocompleteFragment instance
((EditText)placeAutocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setTextSize(10.0f);
UPDATED: 05/26/20
Looks like in latest SDK view id is changed to R.id.places_autocomplete_search_input
Set text color and hint text color to the text in SearchView
I would do this kind of job through the xml layout file. This can be found in the res/layout folder.
You would need to do something similar to the following:
Add this to the parent theme.
<item name="android:editTextColor">@android:color/white</item>
This should change the entered text.
You can also use something like this:
<item name="android:textColorHint">@android:color/white</item>
It will change the hint text for the SearchView.
Hope this helps :)
Related Topics
Android Shape Border with Gradient
Android Webview VS Phone Browser
How to Use Edittext Ontextchanged Event When I Press the Number
Android Cardview Remove Padding
Relocate Google Logo in Mapview
Android: Drawing Custom Shapes
Android/Eclipse Panic: Could Not Open
How to Know If a Fragment Is Visible
Android: Total Height of Scrollview
How to Detect Bottom Soft Navigation Bar Available in Android Programmatically
Creating a Product Sdk: How to Add a Native Lib (.So) and a Jar with the Sdk I am Creating
Passing JSONobject into Another Activity
Multiple Apps Use Same Content Provider
Video Compression on Android Using New Mediacodec Library
Proxy Which Requires Authentication with Android Emulator