0

How to change a "Find my location" icon in a GoogleMaps in Android?

enter image description here

I want to change this icon to custom. Had tried with a Fragment extending, but probably doesn't have a right result.

D.K.
  • 1,315
  • 2
  • 11
  • 20

1 Answers1

1

Not sure what you mean by "doesn't have a right result" but this works fine:

public class MapsActivity extends FragmentActivity {

    ...

    public static class MapFragment extends SupportMapFragment {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = super.onCreateView(inflater, container, savedInstanceState);

            View locationButton = ((View) view.findViewById(1).getParent()).findViewById(2);

            if (locationButton != null) {
                Drawable drawable = getActivity().getApplicationContext()
                        .getResources().getDrawable(R.drawable.ic_launcher);

                locationButton.setBackgroundDrawable(drawable);
            }

            return view;
        }
    }

}

Using your custom layout:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/map"
          android:name="com.example.map.MapsActivity$MapFragment"/>

Source

Community
  • 1
  • 1
Simas
  • 43,548
  • 10
  • 88
  • 116