导航抽屉不切换活动但得到选择

时间:2019-05-01 08:56:32

标签: android android-fragments android-intent navigation

当我单击导航抽屉菜单时,抽屉将关闭但不执行任何操作。就我而言,它必须移至另一个活动/祝酒,但没有任何工作完成。点击操作已执行,但未获得响应。

我希望通过单击导航菜单来更改活动。 建议进行必要的更改以使抽屉用作活动切换器

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener,NavigationView.OnNavigationItemSelectedListener
{

    private DrawerLayout drawer;

    private WebView webView;
    private String currentURL = "";
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // code for side bar

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        drawer = findViewById(R.id.drawer_layout);
        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setVerticalFadingEdgeEnabled(true);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
                R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();         

        webView = findViewById(R.id.webView);
        swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
        swipe.setOnRefreshListener((SwipeRefreshLayout.OnRefreshListener) this);

        // Define url that will open in webview
        String webViewUrl = "http://www.tekies.online";

        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        webView.setScrollbarFadingEnabled(false);
        // webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setPluginState(PluginState.ON);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setSupportZoom(true);

    }


    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        //here is the main place where we need to work on.
        int id=item.getItemId();
        switch (id){

            case R.id.nav_home:
                Intent h= new Intent(this,MainActivity.class);
                startActivity(h);
                break;
            case R.id.nav_profile:
                Intent i= new Intent(this,settings.class);
                startActivity(i);
                break;
            case R.id.nav_chat:
                Intent g= new Intent(this,settings.class);
                startActivity(g);
                break;
            case R.id.nav_share:
                Toast.makeText(getApplicationContext(), "No Link to Share!", Toast.LENGTH_SHORT).show();
                break;
            case R.id.nav_send:
                String link = "http://tekies.online/app";
                Intent referIntent = new Intent(Intent.ACTION_SEND);
                referIntent.setType("text/plain");
                referIntent.putExtra(Intent.EXTRA_TEXT,link); // your above url
                startActivity(Intent.createChooser(referIntent, "Share link using...."));
                break;
            case R.id.nav_message:
                Intent m= new Intent(this,settings.class);
                startActivity(m);
                break;
            case R.id.rate:
                Toast.makeText(getApplicationContext(), "Rate us!", Toast.LENGTH_SHORT).show();
                break;
            case R.id.exit:
                AlertDialog.Builder dialog = new AlertDialog.Builder(this);
                dialog.setTitle("Exit App Confirmation");
                dialog.setMessage("Are you sure ?");
                dialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        onBackPressed();
                        Toast.makeText(getApplicationContext(), "App Closed!", Toast.LENGTH_SHORT).show();
                    }
                });
                dialog.setCancelable(false);
                dialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        Toast.makeText(getApplicationContext(), "Operation Canceled!", Toast.LENGTH_SHORT).show();
                    }
                }).show();
                break;

        }
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

}

0 个答案:

没有答案