2016-10-10 13 views
0

何らかの理由で、SearchViewでタイプフェイスを設定できません。Android - SearchView - setTypefaceが利用できない

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

私はXMLでこのようにそれを定義した:SearchViewは、あなたが最初に見つける必要があるのTextViewが含まれてい

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

答えて

1

は、ここに私のコードは、フォントを変更しようとすることですこのようにTypefaceを変更してください。

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

+0

確かにはるかに優れています:)ありがとう! – Isabelle

1

のTextView検索テキスト=(のTextView)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)を参照してください

。 タイプフェイスタイプ= Typeface.createFromAsset(getAssets()、 "fonts/siemreap.ttf");searchText.setTypeface(type);

+1

少し試してみてください。彼らはあなたの提案を知っています。それに文脈を与えなさい。 – Nightforce2

関連する問題