Android - SearchView - setTypeface不可用

【Android - SearchView - setTypeface不可用】炒沙作縻终不饱,缕冰文章费工巧。这篇文章主要讲述Android - SearchView - setTypeface不可用相关的知识,希望能为你提供帮助。
出于某种原因,我无法在SearchView上设置Typeface。这是我尝试更改字体的代码:

searchView = findViewById(R.id.searchview_invite_friends_search_contact); Typeface myFont = Typeface.createFromAsset(getAssets(),"fonts/myFont.ttf"); searchView.setTypeface(myFont);

我在xml中将它定义为:
< SearchView android:id="@+id/searchView" android:layout_width="match_parent" android:queryHint="@string/searchview_invite_friends_search_contact" android:iconifiedByDefault="false" android:layout_centerHorizontal="true" android:background="@android:color/white" android:searchIcon="@drawable/icon_search" android:focusable="false" android:layout_height="45dp" android:queryBackground="@color/transparent" android:gravity="center_horizontal" >

答案SearchView包含一个TextView,您首先要查找它以更改其字体。
TextView searchText = (TextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); searchText.setTypeface(< your Typeface> );

这适用于v7 Android支持库中的SearchView。
对于android.widget包中的普通SearchView,请参阅https://stackoverflow.com/a/30915643/3233251
另一答案TextView searchText =(TextView)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); 字体类型= Typeface.createFromAsset(getAssets(),“fonts / siemreap.ttf”); searchText.setTypeface(类型);

    推荐阅读