2016-06-13 3 views
1

В настоящее время я работаю над google map api. Я хочу добавить панель инструментов/панель действий в свой фрагмент карты.Добавить панель инструментов в действие фрагмента

пожалуйста, проверьте изображение в ссылке ниже: -

This is the Screen shot please check this out

это мой файл макета .xml

<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`enter code here`="match_parent" 
     android:layout_height="match_parent" 
     tools:context="com.android.bhavin04.MapsActivity" 
     /> 

мой MaintActivity расширяет FragmentActivity и реализует OnMapReadyCallback. Как добавить панель инструментов в мое основное действие. помощь будет оценена.

основной код активность:

package com.android.bhavin04.ganeshutsavmumbai; 

import android.app.Dialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.content.pm.PackageManager; 
import android.graphics.Point; 
import android.location.LocationManager; 
import android.provider.Settings; 
import android.support.v4.app.ActivityCompat; 
import android.support.v4.app.FragmentActivity; 
import android.os.Bundle; 
import android.support.v7.app.AlertDialog; 
import android.widget.Toolbar; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.UiSettings; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.LatLngBounds; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 
import com.pushbots.push.Pushbots; 

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    private LatLngBounds Mumbai = new LatLngBounds(
      new LatLng(-44, 113), new LatLng(19.075984, 72.877656)); 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 

     Pushbots.sharedInstance().init(this); 




     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 

     mMap = googleMap; 

     mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Mumbai.getCenter(), 14)); 

     if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 

      return; 
     } 
     // mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
     mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
     mMap.setMyLocationEnabled(true); 
     mMap.setTrafficEnabled(true); 

     LatLng Mumbai = new LatLng(19.075979, 72.879696); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(Mumbai)); 


    } 
    } 

ответ

0

Расширьте свою деятельность с ActionBarActivity вместо FragmentActivity. (MainActivity расширяет ActionBarActivity)

ActionBarActivity простирается от FragmentActivity, следовательно, он будет работать.

0

Использование AppCompatActivity, который простирался от FragmentActivity, и вы можете создать свой макет что-то, как показано ниже:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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" 
tools:context="com.android.bhavin04.MapsActivity"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:background="?attr/colorPrimary" 
    android:elevation="6dp" 
    android:minHeight="?attr/actionBarSize" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

<FrameLayout 
    android:id="@+id/container_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@id/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="com.android.bhavin04.MapsActivity" /> 
</FrameLayout> 
</RelativeLayout> 

Приведенный выше код XML содержит Toolbar, которые могут быть настроены в любом случае вы хотите, и может быть использован в качестве ActionBar.

+0

это работает большое спасибо ..... :) –

+0

@BhavinHimmatGoswami Пожалуйста, примите ответ –

Смежные вопросы