123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package com.example.myapplication.ui;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import androidx.annotation.NonNull;
- import androidx.appcompat.widget.Toolbar;
- import androidx.drawerlayout.widget.DrawerLayout;
- import androidx.fragment.app.FragmentManager;
- import androidx.fragment.app.FragmentTransaction;
- import androidx.navigation.NavController;
- import androidx.navigation.Navigation;
- import androidx.navigation.ui.AppBarConfiguration;
- import androidx.navigation.ui.NavigationUI;
- import com.example.myapplication.R;
- import com.example.myapplication.ui.list.PullToRefreshFragment;
- import com.example.myapplication.ui.slideshow.SlideshowFragment;
- import com.google.android.material.navigation.NavigationView;
- public class MainActivity extends BaseActivity {
- private AppBarConfiguration mAppBarConfiguration;
- FragmentManager fragmentManager;
- FragmentTransaction fragmentTransaction;
- PullToRefreshFragment pullToRefreshFragment;
- SlideshowFragment slideshowFragment;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Toolbar toolbar = findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- /*FloatingActionButton fab = findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
- .setAction("Action", null).show();
- }
- });*/
- DrawerLayout drawer = findViewById(R.id.drawer_layout);
- NavigationView navigationView = findViewById(R.id.nav_view);
- // Passing each menu ID as a set of Ids because each
- // menu should be considered as top level destinations.
- mAppBarConfiguration = new AppBarConfiguration.Builder(
- R.id.nav_pullToRefresh, R.id.nav_slideshow, R.id.nav_slideshow,
- R.id.nav_tools, R.id.nav_jzvd, R.id.nav_send)
- .setDrawerLayout(drawer)
- .build();
- NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
- NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
- NavigationUI.setupWithNavController(navigationView, navController);
- fragmentManager = getSupportFragmentManager();
- pullToRefreshFragment = new PullToRefreshFragment();
- slideshowFragment = new SlideshowFragment();
- navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
- @Override
- public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
- switch (menuItem.getItemId()) {
- case R.id.nav_pullToRefresh:
- fragmentTransaction = fragmentManager.beginTransaction();
- fragmentTransaction.replace(R.id.nav_host_fragment, pullToRefreshFragment).commit();
- break;
- case R.id.nav_LRecyclerView:
- startActivity(new Intent(MainActivity.this, com.lzx.demo.MainActivity.class));
- break;
- case R.id.nav_slideshow:
- fragmentTransaction = fragmentManager.beginTransaction();
- fragmentTransaction.replace(R.id.nav_host_fragment, slideshowFragment).commit();
- break;
- }
- return false;
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- @Override
- public boolean onSupportNavigateUp() {
- NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
- return NavigationUI.navigateUp(navController, mAppBarConfiguration)
- || super.onSupportNavigateUp();
- }
- }
|