2016-04-04 13 views
10

私は現在取り組んでいるプロジェクトでgoogleが提供するPlaceAutocompleteFragmentを使用しています。しかし問題は、私がオートコンプリートウィジェットから選択した地名を表示する必要がありますが、ウィジェットのデフォルトのテキストサイズが大きすぎるためにテキスト全体が表示されないことです。だから、独自のカスタム検索UIを作成せずにPlaceAutocompleteFragmentのtextsizeを変更する方法はありますか?アンドロイドでオートコンプリートの場所のテキストサイズを変更するには?

私のXMLコード:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.baldysns.capedbaldy.materialdesigntest.activity.DrawerMainActivity" 
    tools:openDrawer="start"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:id="@+id/container_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/toolbar_drawer" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="?attr/colorPrimary" 
       android:minHeight="?attr/actionBarSize" 
       app:popupTheme="@style/AppTheme.PopupOverlay"> 

       <LinearLayout 
        android:id="@+id/lnr_google_searchbar" 
        android:layout_width="match_parent" 
        android:layout_height="35dp" 
        android:layout_marginTop="10dp" 
        android:layout_marginBottom="10dp" 
        android:background="@drawable/btn_white_notboerder"> 

        <fragment 
         android:id="@+id/place_autocompletehome_fragment" 
         android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" /> 
       </LinearLayout> 
      </android.support.v7.widget.Toolbar> 
     </LinearLayout> 

     <FrameLayout 
      android:id="@+id/container_body" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

    </LinearLayout> 

    <fragment 
     android:id="@+id/fragment_navigation_drawer" 
     android:name="com.ibaax.com.ibaax.FragmentDrawer" 
     android:layout_width="300dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:layout="@layout/fragment_drawer" 
     tools:layout="@layout/fragment_drawer" /></android.support.v4.widget.DrawerLayout> 

そして、問題のスクリーンショット:

enter image description here

答えて

27

あなたはフォントサイズを変更することができますし、検索ボックスEditTextで好きなフラグメントインスタンスを...これはあなたが

// placeAutocompleteFragment - is my PlaceAutocompleteFragment instance 
((EditText)placeAutocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setTextSize(10.0f); 

Happy_Codingを行う必要がありますどのようにされて使用。あなたが最初のフラグメントのインスタンスを取得する必要がskadosh答えの場合

+0

私の 'placeAutocompleteFragment'が' Linear Layout'の中にあり、 'placeAutocompleteFragment'にテキストを設定する必要があるのはなぜですか?これはこのシナリオでは機能しないからです。助言がありますか。 –

+1

失敗しました.java.lang.RuntimeException:アクティビティを開始できませんでした。ComponentInfo java.lang.ClassCastException:android.widget.LinearLayoutをandroid.widget.EditTextにキャストすることはできません。 –

+0

@dontknowは異なるIDを使用している可能性があります。ビュー。再確認してください。 – Bharatesh

0

あなたのスクリーンショットは、あなたが検索アイコンでマージンやパディングを設定し、アイコンをキャンセルすることを示しています。それを削除して、テキストビュー用のスペースを増やしてください。

また、あなたのテキストビューのサイズに応じて文字サイズを行いますautofittextviewライブラリhttps://github.com/grantland/android-autofittextview)を使用することができます。

+0

しかし、Googleが提供するデフォルトのplaceautocompleteウィジェットを使用しています。私は、ウィジェットでこれらのものを変更する方法があるのか​​と尋ねています。 –

2

最も簡単な

((EditText)findViewById(R.id.place_autocomplete_search_input)).setTextSize(10.0f); 

関連する問題