I have Android's default "Scrolling Activity". The difference is that I have added a SupportMapFragment
to the CollapsingToolbarLayout
. Following is the xml:
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="16dp"
app:expandedTitleMarginBottom="16dp">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.abc.def.ui.activities.tasks.TaskDetailActivity"
tools:showIn="@layout/activity_task_detail"
app:layout_collapseMode="parallax">
</fragment>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="parallax"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
The map displays fine but when I click the marker, the Map Toolbar Buttons hide behind the FloatingActionButton
.
As given here, I tried moving the buttons to other corners but they stopped responding to clicks i.e. I was not redirected to Maps app.
Then I tried extending the SupportMapFragment
, added a custom view containing the two buttons to the fragment. And assigned click listeners to button. Again, no response to clicks. Here is the code from the Fragment which extends SupportMapFragment
.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FrameLayout wrapper = new FrameLayout(inflater.getContext());
View mapView = super.onCreateView(inflater, container, savedInstanceState);
wrapper.addView(mapView);
mCustomView = inflater.inflate(R.layout.toolbar_map, wrapper, false);
wrapper.addView(mCustomView);
return wrapper;
}
@Override
public void onActivityCreated(Bundle bundle) {
super.onActivityCreated(bundle);
if(mCustomView != null){
View clickable1 = mCustomView.findViewById(R.id.toolbar_map_btn_1);
View clickable2 = mCustomView.findViewById(R.id.toolbar_map_btn_2);
clickable1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mLatLng != null){
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?daddr="+mLatLng.latitude+", "+mLatLng.longitude));
startActivity(intent);
}
}
});
clickable2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mLatLng != null){
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?q=loc:"+mLatLng.latitude+", "+mLatLng.longitude));
startActivity(intent);
}
}
});
}
}
Then I tried adding the two buttons to the CollapsingToolbarLayout
. This time I referenced the buttons and assigned the click events in the Activity itself. Again, no success.
Every time, I was able to show the buttons on the map, wherever I wanted, but the clicks didn't work, except in the first case when they were partially hidden behind the FAB.
Please help.