gpt4 book ai didi

java - 在fragment Activity中添加工具栏

转载 作者:太空宇宙 更新时间:2023-11-04 12:31:53 24 4
gpt4 key购买 nike

目前我正在开发 google map api 。我想将工具栏/操作栏添加到我的 map fragment 中。

请检查以下链接中的图片:-

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。如何将工具栏添加到我的主要 Activity 中。我们将不胜感激。

主要 Activity 代码:

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


}
}

最佳答案

ActionBarActivity 而不是 FragmentActivity 扩展您的 Activity。(MainActivity 扩展了 ActionBarActivity)

ActionBarActivity 扩展自 FragmentActivity 因此它可以工作。

关于java - 在fragment Activity中添加工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37791303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com