2017-10-04 3 views
0

Je voudrais ajouter une barre d'outils pour cartographier l'activité. Le problème est que quand je l'exécute l'espace est là mais ne montre pas ma barre d'outils.Barre d'outils dans google map activity

Ceci est mon 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> 

Ceci est le style:

<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="actionMenuTextColor">#fff</item> 
    <item name="android:actionMenuTextColor">#fff</item> 
</style> 

Ceci est 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)); 
    } 
} 

enter image description here

+0

supprimer le style de votre barre d'outils – akhilesh0707

+0

vous avez appliqué le style personnalisé sur votre barre d'outils supprimer 'android: theme = "style @/AppTheme.ActionBar"' et vérifier – akhilesh0707

+0

ISN 't cette bande blanche en capture d'écran de votre barre d'outils? –

Répondre

1

Oui correct, il ne sera pas comment quoi que ce soit à l'intérieur de la barre d'outils, car vous n'avez défini aucune vue à afficher à l'intérieur de la barre d'outils.

Cela signifie que vous pouvez ajouter des vues à l'intérieur de la barre d'outils, par ex.

<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> 

Et vous pouvez modifier les vues dans la barre d'outils en conséquence.

+0

Merci, je l'ai résolu avec un mélange de vos réponses. (Je ne peux pas voter votre réponse parce que ma réputation) –

+0

Haha pas de problème frère. Heureux qu'il a résolu votre problème :-) –

0

Voilà comment je l'ai résolu. (Je ne suis pas besoin de l'icône du hamburger)

<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.ilunion.a_muse.ui.activity.GoogleMapActivity"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimaryDark"> 

      <TextView 
       android:id="@+id/tool_left_title" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_centerVertical="true" 
       android:background="@color/colorPrimaryDark" 
       android:textColor="@color/white" 
       android:text="Title"/> 

    </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> 
+0

Oui, je viens de donner un exemple des points de vue comment vous pouvez ajouter à l'intérieur. Vous pouvez ajouter anyview pour la barre d'outils. Génial que cela a résolu votre problème :-) –