在PlaceAutocompleteFragment中找不到任何可用于更改hint的文本颜色的方法。
PlaceAutocompleteFragment
hint
bhmjp9jg1#
EditText etPlace = (EditText)autocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input); etPlace.setHint("Type your address"); etPlace.setHintTextColor(R.color.primary_text_material_dark);
fcy6dtqo2#
1.将以下文件添加到项目中1.将ThemedAutocompleteSupportFragment而不是AutocompleteSupportFragment添加到布局中1.如果需要,修改下面的fragment_places_autocomplete.xml以适合您的应用主题颜色。重要的是保持android:id属性不变,以便原始AutocompleteSupportFragment可以在内部正确使用它们。ThemedAutocompleteSupportFragment.kt
ThemedAutocompleteSupportFragment
AutocompleteSupportFragment
fragment_places_autocomplete.xml
android:id
ThemedAutocompleteSupportFragment.kt
import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.google.android.libraries.places.widget.AutocompleteSupportFragment class ThemedAutocompleteSupportFragment:AutocompleteSupportFragment() { override fun onCreateView(inflater:LayoutInflater,container:ViewGroup?,savedInstanceState:Bundle?):View? { return inflater.inflate(R.layout.fragment_places_autocomplete,container,false) } }
res/layout/fragment_places_autocomplete.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:focusable="true" android:focusableInTouchMode="true" android:gravity="center" android:layoutDirection="locale" android:orientation="horizontal" android:textDirection="locale"> <ImageButton android:id="@id/places_autocomplete_search_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0" android:background="@null" android:contentDescription="@string/places_autocomplete_search_hint" android:padding="@dimen/places_autocomplete_button_padding" android:src="@drawable/ic_baseline_search_24" app:tint="?android:textColorSecondary" /> <EditText android:id="@id/places_autocomplete_search_input" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@null" android:focusable="false" android:focusableInTouchMode="false" android:hint="@string/places_autocomplete_search_hint" android:inputType="textNoSuggestions" android:lines="1" android:maxLines="1" android:paddingLeft="@dimen/places_autocomplete_search_input_padding" android:paddingRight="@dimen/places_autocomplete_search_input_padding" android:singleLine="true" android:textSize="@dimen/places_autocomplete_search_input_text" /> <ImageButton android:id="@id/places_autocomplete_clear_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0" android:background="@null" android:contentDescription="@string/places_autocomplete_clear_button" android:padding="@dimen/places_autocomplete_button_padding" android:src="@drawable/ic_baseline_clear_24" app:tint="?android:textColorSecondary" /> </LinearLayout>
res/drawable/ic_baseline_clear_24.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:tint="#000000" android:viewportWidth="24" android:viewportHeight="24"> <path android:fillColor="@android:color/white" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" /> </vector>
res/drawable/ic_baseline_search_24.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:tint="#000000" android:viewportWidth="24" android:viewportHeight="24"> <path android:fillColor="@android:color/white" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z" /> </vector>
2条答案
按热度按时间bhmjp9jg1#
fcy6dtqo2#
1.将以下文件添加到项目中
1.将
ThemedAutocompleteSupportFragment
而不是AutocompleteSupportFragment
添加到布局中1.如果需要,修改下面的
fragment_places_autocomplete.xml
以适合您的应用主题颜色。重要的是保持android:id
属性不变,以便原始AutocompleteSupportFragment
可以在内部正确使用它们。ThemedAutocompleteSupportFragment.kt
res/layout/fragment_places_autocomplete.xml
res/drawable/ic_baseline_clear_24.xml
res/drawable/ic_baseline_search_24.xml