1
          AutocompleteSupportFragment autocompleteFragment=(AutocompleteSupportFragment)
            getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
          ImageView searchIcon = (ImageView) 
         ((LinearLayout)autocompleteFragment.getView()).getChildAt(0);

         searchIcon.setImageDrawable(getResources().getDrawable(R.drawable.search));

want to set a customize background for the search box in map

          autocompleteFragment.getView().setBackground(new Drawable));// need help here
evan
  • 5,443
  • 2
  • 11
  • 20
  • See related https://stackoverflow.com/questions/35891667/change-foreground-and-background-color-of-place-autocomplete-fragment – evan Sep 28 '19 at 11:36

1 Answers1

1

Google's documentation says:

By default, the fragment has no border or background. To provide a consistent visual appearance, nest the fragment within another layout element such as a CardView.

So e.g. to give it a quantum_orange look I did this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_gravity="center"
        card_view:cardBackgroundColor="@color/quantum_orange"
        card_view:cardCornerRadius="4dp">

        <fragment
            android:id="@+id/autocomplete_fragment"
            android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </androidx.cardview.widget.CardView>

</LinearLayout>

Otherwise you can just do this:

autocompleteFragment.getView().setBackgroundResource(R.drawable.my_drawable);

or this:

autocompleteFragment.getView().setBackgroundColor(Color.RED);

Alternatively you may want to look into creating your own fully customizable UI using a custom fragment.

Hope this helps you.

evan
  • 5,443
  • 2
  • 11
  • 20