Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - change icon of autocomplete_fragment in google maps

I have an android app using google maps and I wanted a search bar that looks just like the android google maps. Below is my XML code and picture of what I have.

 <android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp">
    <fragment
        android:id="@+id/place_autocomplete_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"/>
</android.support.v7.widget.CardView>

enter image description here

The problem is that I have a navigation drawer that opens when you slide from the left. I want to add the "three horizontal lines" to the search bar like google maps so whenever you click that, the navigation drawer opens as shown below.

enter image description here

So how can I change the "magnifying glass" into "3 horizontal lines" and make the navigation drawer open up on click. Thanks!

like image 959
Parth Bhoiwala Avatar asked Feb 05 '23 11:02

Parth Bhoiwala


1 Answers

You can find the corresponding ImageView and change it's icon and on click event:

PlaceAutocompleteFragment placeAutocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
ImageView searchIcon = (ImageView)((LinearLayout)placeAutocompleteFragment.getView()).getChildAt(0);

// Set the desired icon
searchIcon.setImageDrawable(getResources().getDrawable(R.drawable.yourdrawable));

// Set the desired behaviour on click
searchIcon.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Toast.makeText(MapsActivity.this, "YOUR DESIRED BEHAVIOUR HERE", Toast.LENGTH_SHORT).show();
    }
});
like image 103
antonio Avatar answered Feb 13 '23 03:02

antonio