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>
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.
So how can I change the "magnifying glass" into "3 horizontal lines" and make the navigation drawer open up on click. Thanks!
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();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With