RanjitRock
RanjitRock

Reputation: 1451

How to add search icon over Google maps?

I am using Google maps v2 to draw maps. I need to display a search box on top of the maps which is anchored to top of the screen. I tried many ways to overlay it but it is not working. Is there an API to overlay custom views on maps?

Upvotes: 0

Views: 661

Answers (1)

Jon Zangitu
Jon Zangitu

Reputation: 967

You can use RelativeLayout, for example like this:

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

<EditText
    android:id="@+id/editTextLocation"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="60dp"
    android:layout_marginRight="60dp"
    android:layout_marginTop="13dp"
    android:background="@android:color/white"
    android:hint="@string/search"
    android:imeOptions="actionSearch"
    android:inputType="text"
    android:padding="5dp" />

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/buttonMap"
    android:layout_alignParentTop="true" />

<Button
    android:id="@+id/buttonMap"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:enabled="false"
    >
</Button>

In code, use bringToFront() method.

// show editext over map
mEditText.bringToFront();

Upvotes: 1

Related Questions