如何在android中的地方autocompletefragment中更改文本大小?

问题描述 投票:11回答:4

我正在使用谷歌在我正在进行的项目中提供的PlaceAutocompleteFragment。但问题是我需要显示我从自动完成小部件中选择的地名,但是整个文本没有显示,因为小部件中的默认文本大小太大。那么,有没有什么方法可以在不创建我自己的自定义搜索UI的情况下更改PlaceAutocompleteFragment中的文本大小?

我的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

android textview google-places-api autocompletetextview
4个回答
30
投票

使用片段实例,您可以使用搜索框EditText更改字体大小和任何您想要的...这就是您需要做的

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

4
投票

autoCompleSupportFragment具有EditText属性。哪个可以相应修改。但是,editText的名称不是很清楚。就我而言,它是“一个”

autoCompleteFragment.a.gravity = Gravity.START

所以为了修改文字大小,我做了:

autoCompleteFragment.a.textSize = 14.0f

2
投票

简单

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

在skadosh回答的情况下,您需要先获取片段的实例。


0
投票

您的屏幕截图显示您在搜索图标和取消图标上设置边距或填充。删除它,以便为文本视图腾出更多空间。

您还可以使用autofittextview库(https://github.com/grantland/android-autofittextview),它将根据您的文本视图大小生成文本大小。

© www.soinside.com 2019 - 2024. All rights reserved.