我将 activity 转换为 Fragment Activity 但现在我无法添加操作栏
I convert activity to Fragment Activity but now I can not add Action bar
**
我想添加一个 Google 地图,所以我只是通过扩展 FragmentActivity
将我的普通 Activity class 转换为片段 activity
但是现在我无法添加一个应用程序栏(操作栏)来放置我的后退按钮以导航到上一个 activity
**
public class LocationActivity extends FragmentActivity implements OnMapReadyCallback {
public static final String EXTRA_DATA = "EXTRA_DATA";
Item item;
GoogleMap map;
String title,address,info;
Double lon,lat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
//intialized map fragment
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.google_current_map);
mapFragment.getMapAsync(this);
//getData form serializable
item = (Item) getIntent().getSerializableExtra(EXTRA_DATA);
lat = Double.parseDouble(item.getLatitude());
lon = Double.parseDouble(item.getLongitude());
title = item.getTitle();
address = item.getAddress();
//add string together to show in map
info = String.format("%s /n %s", title, address);
FragmentTransaction mFragmentTransaction = getFragmentManager()
.beginTransaction();
mFragmentTransaction.addToBackStack(null);
}
// this event will enable the back
// function to the button on press
@Override
public void onBackPressed() {
if (getFragmentManager().getBackStackEntryCount() == 0) {
this.finish();
}
else {
getFragmentManager().popBackStack();
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
LatLng Location = new LatLng(lat,lon);
Toast.makeText(this, lat + " "+ lon, Toast.LENGTH_SHORT).show();
map.addMarker(new MarkerOptions().position(Location).title(info));
map.moveCamera(CameraUpdateFactory.newLatLng(Location));
}
}
再次将Fragment
转换为AppCompactActivity
解决了。
**
我想添加一个 Google 地图,所以我只是通过扩展 FragmentActivity
将我的普通 Activity class 转换为片段 activity
但是现在我无法添加一个应用程序栏(操作栏)来放置我的后退按钮以导航到上一个 activity
**
public class LocationActivity extends FragmentActivity implements OnMapReadyCallback {
public static final String EXTRA_DATA = "EXTRA_DATA";
Item item;
GoogleMap map;
String title,address,info;
Double lon,lat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
//intialized map fragment
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.google_current_map);
mapFragment.getMapAsync(this);
//getData form serializable
item = (Item) getIntent().getSerializableExtra(EXTRA_DATA);
lat = Double.parseDouble(item.getLatitude());
lon = Double.parseDouble(item.getLongitude());
title = item.getTitle();
address = item.getAddress();
//add string together to show in map
info = String.format("%s /n %s", title, address);
FragmentTransaction mFragmentTransaction = getFragmentManager()
.beginTransaction();
mFragmentTransaction.addToBackStack(null);
}
// this event will enable the back
// function to the button on press
@Override
public void onBackPressed() {
if (getFragmentManager().getBackStackEntryCount() == 0) {
this.finish();
}
else {
getFragmentManager().popBackStack();
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
LatLng Location = new LatLng(lat,lon);
Toast.makeText(this, lat + " "+ lon, Toast.LENGTH_SHORT).show();
map.addMarker(new MarkerOptions().position(Location).title(info));
map.moveCamera(CameraUpdateFactory.newLatLng(Location));
}
}
再次将Fragment
转换为AppCompactActivity
解决了。