How to set SearchView TextSize?

人走茶凉 提交于 2019-11-28 21:20:19

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));

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"/>

When using ActionBarSherlock you have to do this:

    AutoCompleteTextView searchTextView = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
    searchTextView.setTextColor(getResources().getColor(R.color.search_text_color));
Sneg

Check this answer Can we limit the number of character in edittext of SearchView in Android?. It uses SearchView.OnQueryTextListener in order to check if exceeded the limit.

Though AutoCompleteTextView is superclass of SearchAutoComplete, SearchView use SearchAutoComplete rather than AutoCompleteTextView. use it and do more.

SearchView searchView=...;
SearchView.SearchAutoComplete autoComplete= searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
float textSpSize=10.f;
if (autoComplete!=null){
    autoComplete.setTextSize(textSpSize);
   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!