我正在使用Google目前正在研究的项目中提供的PlaceAutocompleteFragment。但是问题是我需要显示我从自动完成小部件中选择的地名,但由于小部件中的默认textsize太大,因此无法显示整个文本。因此,有什么方法可以在PlaceAutocompleteFragment中更改文本大小而无需创建自己的自定义搜索UI?
我的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>
和问题的屏幕截图:
最佳答案
使用片段实例,您可以通过搜索框EditText
来更改字体大小以及所需的字体。这是您需要做的
// placeAutocompleteFragment - is my PlaceAutocompleteFragment instance
((EditText)placeAutocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setTextSize(10.0f);
更新:05/26/20
看起来在最新的SDK View ID已更改为
R.id.places_autocomplete_search_input