2017-06-01 14 views
1

私はに次のようなSearchViewを実装しています。テキスト入力は、下の図のように上から切り取ってあります。どんなことをしてもtextSize私は置いていますが、何も変わりません。SearchViewの変更TextSize

enter image description here

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="32dp" 
    android:gravity="center_vertical" 
    android:layout_marginTop="10dp"> 
    <SearchView 
     android:id="@+id/search_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:textSize="12sp"/> 
</LinearLayout> 
+0

あなたは文字をカットするいくつかのパディングがあります。完全なXML – tompadre

+0

を提供しましたこのソリューションを試してみましたかhttps://stackoverflow.com/a/12942258/4856245 –

+0

私の質問にはXMLに追加情報を追加しました – hotspring

答えて

2

あなたがこの方法で

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

をごSearchViewtextSizeに合格する必要があり、この1

をあなたのXMLを更新してみてください
+0

私の質問にはXMLに追加情報が追加されています。 – hotspring

+0

は必要ありません。私のコードを試して、魔法を見てください。 :) –

+0

ネイティブアプリで私のために働いて、私はxamarinについて考えていない。 –

0
sv= (SearchView) findViewById(R.id.search_view); 
TextView searchText = (TextView)    
sv.findViewById(android.support.v7.appcompat.R.id.search_src_text); 
searchText.setTextSize(TypedValue.COMPLEX_UNIT_SP,12); 
関連する問題