是否可以使用bottomNavigationBar打开bottomSheetDialog?

时间:2019-05-21 09:51:01

标签: java android bottomnavigationview bottom-sheet

当我单击底部导航项时,我想打开底部对话框(Yandex Maps android app之类。背景始终有地图。底部导航项仅打开底部对话框)。

yandex view 但是我做不到。有可能吗?

我尝试了一些片段方法,但应用程序崩溃了。

activity_main.xml

<?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=".MainActivity" >

    <com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/berkay"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </com.mapbox.mapboxsdk.maps.MapView>

    <FrameLayout
        android:id="@+id/frame_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/main_bottom">

    </FrameLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/main_bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/navigation"
        android:background="?android:attr/windowBackground">
    </android.support.design.widget.BottomNavigationView>


</RelativeLayout>

底部导航项选择

private BottomNavigationView.OnNavigationItemSelectedListener navListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {

            Fragment selectedFragment = null;

            switch (menuItem.getItemId()){
                case R.id.navigation_map:

                    break;
                case R.id.navigation_search:
                    SearchFragment searchFragment = new SearchFragment();
                    searchFragment.show(getSupportFragmentManager(),"SearchFragment");
                    break;
                case R.id.navigation_event:
                    selectedFragment = new EventsFragment();
                    break;
                case R.id.navigation_profile:
                    selectedFragment = new ProfileFragment();
                    break;
            }

            getSupportFragmentManager().beginTransaction().replace(R.id.frame_main,selectedFragment).commit();

            return true;
        }
    };

SearchFragment.java

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapboxMap;

public class SearchFragment extends BottomSheetDialogFragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_search,container,false);
        return v;
    }
}

SearchFragment情况下的Logcat错误

  

java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'java.lang.Class java.lang.Object.getClass()'

1 个答案:

答案 0 :(得分:0)

我做到了。

SELECT [Market], [MEDIAN_F&B], [MEDIAN_SPA]
FROM 
    (SELECT 
    DISTINCT [Market], CASE [F&B] WHEN 0 THEN 0 ELSE 1 END + CASE [SPA] WHEN 0 THEN 0 ELSE 1 END g,   
    PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY ([F&B])) OVER (PARTITION BY [Market], CASE [F&B] WHEN 0 THEN 0 ELSE 1 END ) AS [MEDIAN_F&B],
    PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY ([SPA])) OVER (PARTITION BY [Market], CASE [SPA] WHEN 0 THEN 0 ELSE 1 END ) AS [MEDIAN_SPA]
    FROM #MyTempTable    
) t
WHERE g=2