当前位置: 首页 > 知识库问答 >
问题:

如何在没有ActionBar的应用程序中使用Mapbox PlacePicker活动?

郗河
2023-03-14

我正在调查我当前Android应用程序中的优秀Mapbox库。

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.hide()' on a null object reference
        at com.mapbox.mapboxsdk.plugins.places.picker.ui.PlacePickerActivity.onCreate(PlacePickerActivity.java:65)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
<resources>
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>
// MAPBOX
implementation "com.mapbox.mapboxsdk:mapbox-android-sdk:$mapBoxSdkVersion"
implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-traffic:$mapBoxTrafficVersion"
implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-places:$mapBoxPlacesVersion"

    mapBoxSdkVersion = "6.8.1"
    mapBoxTrafficVersion = "0.6.0"
    mapBoxPlacesVersion = "0.6.0"
   /**
     * @param toolbar
     */
    private void manageToolbar(final Toolbar toolbar) {
        mToolbar = toolbar;
        setSupportActionBar(mToolbar);

    }

我的活动布局类似于这样:-

<?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:mapbox="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=".main.Main">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:layout_alignParentTop="true"
        app:layout_scrollFlags="scroll|enterAlways">

        <android.support.v7.widget.Toolbar
            android:id="@+id/crr_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:minHeight="?android:attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_collapseMode="parallax"
            app:layout_scrollFlags="scroll|enterAlways">

            <ProgressBar
                android:id="@+id/toolbar_progress"
                android:layout_width="?android:attr/actionBarSize"
                android:layout_height="?android:attr/actionBarSize"
                android:layout_gravity="end"
                android:indeterminate="true"
                android:indeterminateTint="@android:color/white"
                android:indeterminateTintMode="src_in"
                android:padding="5dp"
                android:rotation="0.9" />

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        mapbox:mapbox_cameraTargetLat="40.73581"
        mapbox:mapbox_cameraTargetLng="-73.99155"
        mapbox:mapbox_cameraZoom="11"
        mapbox:mapbox_styleUrl="@string/mapbox_style_mapbox_streets" />

</RelativeLayout>

为什么Mapbox PlacePickerActivity不能隐藏我的操作栏/工具栏?

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Hide any toolbar an apps theme might automatically place in activities. Typically creating an
    // activity style would cover this issue but this seems to prevent us from getting the users
    // application colorPrimary color.
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    **getSupportActionBar().hide(); //!!! NULL POINTER HERE**
    setContentView(R.layout.mapbox_activity_place_picker);

    if (savedInstanceState == null) {
      accessToken = getIntent().getStringExtra(PlaceConstants.ACCESS_TOKEN);
      options = getIntent().getParcelableExtra(PlaceConstants.PLACE_OPTIONS);
    }

    // Initialize the view model.
    viewModel = ViewModelProviders.of(this).get(PlacePickerViewModel.class);
    viewModel.getResults().observe(this, this);

    bindViews();
    addBackButtonListener();
    addChosenLocationButton();
    customizeViews();

    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(this);
  }

共有1个答案

谢昂雄
2023-03-14

如何在AppCompat v.7中显示和隐藏ActionBar

如何在AppCompat v.7中显示和隐藏ActionBar

 类似资料:
  • 问题内容: 我在我的App中有不同之处,在所有这些方面,我都不需要。我找不到如何禁用它。我试图找到一个属性将其应用于,但到目前为止我什么都没找到。有人可以帮我吗? 问题答案: 哈哈,我刚才也被困在这一点上,所以很高兴我可以为您提供解决方案,至少对我有用:) 您想要做的是在values / styles.xml中定义一个新样式,如下所示 只有NoActionBar样式对您来说才有意义。最后,您必须在

  • 我的应用程序中有不同的< code >活动,我不想要所有这些< code >活动栏。我找不到关闭它的方法。我试图找到一个属性,将其应用到< code>main_activity.xml中,但是到目前为止,我什么也没有找到。有人能帮我吗?

  • 请建议与android画中画模式相关的问题,如果我的应用程序有堆栈像家庭活动- 或 我想在应用程序图标启动时关闭PIP活动(PlayerActivity)。由于PIP活动在单独的任务中运行,如何关闭应用程序运行的所有其他任务?

  • 另外,是否有可能在保留用户数据的同时清除使用ADB的应用程序的缓存?似乎清除了所有用户数据。我只想清除缓存。 我之所以这么问是因为我正在对一些用户应用程序进行性能测试。为了使每个测试有效,我希望确保没有任何用户应用程序有任何任务,活动,服务和缓存已经在后台。

  • 问题内容: 我们已经发布了几年前基于JDK 5开发的分布式Web应用程序。 JMX将如何帮助该应用程序? 1)它可以帮助我监视性能(内存,CPU,网络和磁盘IO)吗? 2)如果是这样,则应用程序部署在多台服务器中,如何在一个仪表板中进行监视? 3)是否必须对现有应用程序进行任何新的代码更改,或者可以在不更改代码的情况下进行监视? 4)除了性能监控,我们还能做什么?由于名称是Management E

  • 在所有活动上添加导航抽屉的有效方法是什么?我不想在所有的活动和它们的布局中重复导航抽屉的代码。有没有可能以某种方式添加导航。BaseActivity(自定义类)中的抽屉,然后每个其他活动都将扩展BaseActivity以便拥有导航抽屉?