2016-04-04 22 views
10

Tôi đang sử dụng PlaceAutocompleteFragment được cung cấp bởi google trong một dự án mà tôi đang làm việc ngay bây giờ. Nhưng vấn đề là tôi cần hiển thị tên địa điểm mà tôi đã chọn từ tiện ích tự động điền nhưng toàn bộ văn bản không hiển thị vì văn bản mặc định trong tiện ích con quá lớn. Vì vậy, có cách nào tôi có thể thay đổi văn bản trong PlaceAutocompleteFragment mà không cần tạo giao diện người dùng tìm kiếm tùy chỉnh của riêng tôi không?Làm thế nào để thay đổi kích thước văn bản ở những nơi tự động hoàn thành trong android?

Mã của tôi 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> 

Và một ảnh chụp màn hình của vấn đề:

enter image description here

Trả lời

27

Sử dụng Ví dụ đoạn bạn có thể thay đổi kích thước phông chữ và bất cứ điều gì bạn muốn với hộp Search EditText .. Đây là cách bạn cần phải làm

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

Happy_Coding;

+0

Điều gì xảy ra nếu 'placeAutocompleteFragment' của tôi nằm trong' Linear Layout' và tôi cần đặt văn bản thành 'placeAutocompleteFragment' vì điều này không hoạt động trong trường hợp này. Bất kỳ đề xuất. –

+1

Nó không thành công..java.lang.RuntimeException: Không thể bắt đầu hoạt động ComponentInfo java.lang.ClassCastException: android.widget.LinearLayout không thể truyền tới android.widget.EditText –

+0

@dontknow có thể bạn đang sử dụng id khác hoặc từ các đoạn khác nhau lượt xem. xin vui lòng kiểm tra lại. – Bharatesh

0

ảnh chụp màn hình của bạn cho thấy rằng bạn thiết lập margin hoặc padding vào biểu tượng tìm kiếm và biểu tượng hủy. loại bỏ nó để nó tạo thêm không gian cho chế độ xem văn bản.

Bạn cũng có thể sử dụng autofittextviewthư viện (https://github.com/grantland/android-autofittextview) mà sẽ làm cho kích thước văn bản theo kích thước xem văn bản của bạn.

+0

Nhưng tôi đang sử dụng tiện ích con chưa hoàn thành mặc định được cung cấp bởi google. Tôi hỏi là có cách nào để thay đổi những thứ này trong widget. –

2

đơn giản

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

trong trường hợp skadosh câu trả lời bạn cần phải đầu tiên được thể hiện của đoạn.

Các vấn đề liên quan