I would like add a toolbar to map activity. The problem is that when I run it the space is there but don't show my toolbar.
This is my xml:
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.ruben.my_app.ui.activity.GoogleMapActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.ActionBar">
</android.support.v7.widget.Toolbar>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="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"
tools:context=".ui.activity.GoogleMapActivity" />
</LinearLayout>
This is the style:
<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionMenuTextColor">#fff</item>
<item name="android:actionMenuTextColor">#fff</item>
</style>
This is GoogleMapActivity.java:
public class GoogleMapActivity extends AppCompatActivity implements OnMapReadyCallback {
@BindView(R.id.toolbar)Toolbar toolbar;
private GoogleMap mMap;
public static int color = 0xFF1C1C1C;
public static int textColor = 0xFFFFFFFF;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_map);
setSupportActionBar(toolbar);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng madrid = new LatLng(40.428462, -3.704952);
mMap.addMarker(new MarkerOptions().position(madrid).title("Madrid"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(madrid,17));
}
}
Yes correct, it won't show anything inside the toolbar because you have not set any views to show inside the toolbar.
That means you can add views inside the toolbar e.g.
<android.support.v7.widget.Toolbar
android:id="@+id/top_bar_activity_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/tool_bar_height"
android:theme="@style/AppTheme.ActionBar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/toolbar_left_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:gravity="start"
android:src="@drawable/hamburger"/>
<TextView
android:id="@+id/tool_left_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/toolbar_left_icon"
android:text="Title"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
And you can modify the views inside the toolbar accordingly.