小编A H*_*han的帖子

向操作栏添加后退按钮

正如标题所说,我想在我的'MapsActivity.java'中添加一个后退按钮到操作栏,每当点击后退按钮时,我希望用户转到父活动.我尝试使用这里提到的代码:添加回操作栏的按钮

现在每当我到达此页面时,我都会收到一条消息"很遗憾应用已经停止".注意:当我使用以下代码时,应用程序才会崩溃:

ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
Run Code Online (Sandbox Code Playgroud)

MapsActivity.java: -

    package com.example.haseeb.memorableplaces;

import android.app.ActionBar;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;

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.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // 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);

        ActionBar actionBar = …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-studio

2
推荐指数
1
解决办法
2881
查看次数