单击按钮时抽屉不会关闭

时间:2021-05-26 02:45:20

标签: android navigation-drawer slidingdrawer

我希望我的导航抽屉在按下其中的按钮时关闭,但它没有关闭。我试过 drawerLayout.closeDrawer(GravityCompat.START) 和 drawerLayout.closeDrawers();但这些在这方面似乎不起作用。

我的 MainActivity.java

library(shiny)
library(ggplot2)
library(dplyr)


shinyServer(function(input, output) {

    output$ufoPlot <- renderPlot({
        
        ufo_data_filter <- filter(ufo_data, Country == input$Country)
        ggplot(data = ufo_data_filter) +
            geom_bar(mapping = aes(x = Shape))+
            labs(
                title = "Number of Different Shaped UFO Observations",
                x = "Shape of UFO Sighted",
                y = "Number of Observations in 2016"
            )
    })
})

这是我的 activity_main.xml 我的组件顺序不正确吗?在这方面重要吗?

    @SuppressLint("NonConstantResourceId")
    @Override
    public boolean onNavigationItemSelected(@NonNull @NotNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.nav_share:

                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                String shareBodyText = "Check out this awesome store at https://google.com";
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out our store");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
                startActivity(Intent.createChooser(sharingIntent, "Sharing Option"));
                return true;
          }
drawerLayout.closeDrawer(GravityCompat.START);

      return true;
}

    private void setNavigationViewListener() {
        NavigationView navigationView = findViewById(R.id.nv);
        navigationView.setNavigationItemSelectedListener(this);
    }

    @SuppressLint({"SetJavaScriptEnabled", "NonConstantResourceId"})
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }

                return super.onOptionsItemSelected(item);


    }


0 个答案:

没有答案