android.support.design.widget.NavigationView.setNavigationItemSelectedListener()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中android.support.design.widget.NavigationView.setNavigationItemSelectedListener()方法的一些代码示例,展示了NavigationView.setNavigationItemSelectedListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NavigationView.setNavigationItemSelectedListener()方法的具体详情如下:
包路径:android.support.design.widget.NavigationView
类名称:NavigationView
方法名:setNavigationItemSelectedListener

暂无

代码示例

代码示例来源:origin: chrisbanes/cheesesquare

private void setupDrawerContent(NavigationView navigationView) {
  navigationView.setNavigationItemSelectedListener(
      new NavigationView.OnNavigationItemSelectedListener() {
    @Override
    public boolean onNavigationItemSelected(MenuItem menuItem) {
      menuItem.setChecked(true);
      mDrawerLayout.closeDrawers();
      return true;
    }
  });
}

代码示例来源:origin: naman14/Timber

private void setupDrawerContent(NavigationView navigationView) {
  navigationView.setNavigationItemSelectedListener(
      new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(final MenuItem menuItem) {
          updatePosition(menuItem);
          return true;
        }
      });
}

代码示例来源:origin: bingoogolapple/BGARefreshLayout-Android

@Override
protected void setListener() {
  mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
    @Override
    public boolean onNavigationItemSelected(MenuItem menuItem) {

代码示例来源:origin: north2016/T-MVP

@Override
public void initView() {
  ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mViewBinding.dlMainDrawer, R.string.drawer_open, R.string.drawer_close);
  mDrawerToggle.syncState();
  mViewBinding.dlMainDrawer.addDrawerListener(mDrawerToggle);
  mViewBinding.nvMainNavigation.setNavigationItemSelectedListener(this);
}

代码示例来源:origin: mxn21/FlowingDrawer

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.fragment_menu, container,
      false);
  ivMenuUserProfilePhoto = (ImageView) view.findViewById(R.id.ivMenuUserProfilePhoto);
  NavigationView vNavigation = (NavigationView) view.findViewById(R.id.vNavigation);
  vNavigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
    @Override
    public boolean onNavigationItemSelected(MenuItem menuItem) {
      Toast.makeText(getActivity(),menuItem.getTitle(),Toast.LENGTH_SHORT).show();
      return false;
    }
  }) ;
  setupHeader();
  return  view ;
}

代码示例来源:origin: MindorksOpenSource/android-mvp-architecture

void setupNavMenu() {
  View headerLayout = mNavigationView.getHeaderView(0);
  mProfileImageView = (RoundedImageView) headerLayout.findViewById(R.id.iv_profile_pic);
  mNameTextView = (TextView) headerLayout.findViewById(R.id.tv_name);
  mEmailTextView = (TextView) headerLayout.findViewById(R.id.tv_email);
  mNavigationView.setNavigationItemSelectedListener(
      new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
          mDrawer.closeDrawer(GravityCompat.START);
          switch (item.getItemId()) {
            case R.id.nav_item_about:
              mPresenter.onDrawerOptionAboutClick();
              return true;
            case R.id.nav_item_rate_us:
              mPresenter.onDrawerRateUsClick();
              return true;
            case R.id.nav_item_feed:
              mPresenter.onDrawerMyFeedClick();
              return true;
            case R.id.nav_item_logout:
              mPresenter.onDrawerOptionLogoutClick();
              return true;
            default:
              return false;
          }
        }
      });
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

/**
 * 初始化NavigationView
 */
private void initNavigationView() {
  mNavigationView.setNavigationItemSelectedListener(this);
  View headerView = mNavigationView.getHeaderView(0);
  CircleImageView mUserAvatarView = (CircleImageView) headerView.findViewById(R.id.user_avatar_view);
  TextView mUserName = (TextView) headerView.findViewById(R.id.user_name);
  TextView mUserSign = (TextView) headerView.findViewById(R.id.user_other_info);
  ImageView mSwitchMode = (ImageView) headerView.findViewById(R.id.iv_head_switch_mode);
  //设置头像
  mUserAvatarView.setImageResource(R.drawable.ic_hotbitmapgg_avatar);
  //设置用户名 签名
  mUserName.setText(getResources().getText(R.string.hotbitmapgg));
  mUserSign.setText(getResources().getText(R.string.about_user_head_layout));
  //设置日夜间模式切换
  mSwitchMode.setOnClickListener(v -> switchNightMode());
  boolean flag = PreferenceUtil.getBoolean(ConstantUtil.SWITCH_MODE_KEY, false);
  if (flag) {
    mSwitchMode.setImageResource(R.drawable.ic_switch_daily);
  } else {
    mSwitchMode.setImageResource(R.drawable.ic_switch_night);
  }
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_overscroll_demo);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle(R.string.recycler_view_demo_title);
  setSupportActionBar(toolbar);
  DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  drawer.setDrawerListener(toggle);
  toggle.syncState();
  NavigationView navigationView = (NavigationView) findViewById(R.id.drawer_nav);
  navigationView.setNavigationItemSelectedListener(this);
  if (savedInstanceState == null) {
    getFragmentManager().beginTransaction()
        .add(R.id.fragment_placeholder, new RecyclerViewDemoFragment())
        .commit();
  }
}

代码示例来源:origin: iammert/MaterialIntroView

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  if (savedInstanceState == null)
    getSupportFragmentManager()
        .beginTransaction()
        .add(R.id.container, new MainFragment())
        .commit();
  DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  drawer.setDrawerListener(toggle);
  toggle.syncState();
  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);
}

代码示例来源:origin: Clans/FloatingActionButton

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main_activity);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  mDrawerLayout.addDrawerListener(toggle);
  toggle.syncState();
  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(navigationItemSelectedListener);
  if (savedInstanceState == null) {
    getSupportFragmentManager().beginTransaction()
        .add(R.id.fragment, new HomeFragment()).commit();
  }
  navigationView.setCheckedItem(R.id.home);
}

代码示例来源:origin: arimorty/floatingsearchview

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);
  showFragment(new SlidingSearchResultsExampleFragment());
}

代码示例来源:origin: Rukey7/MvpApp

/**
 * 初始化 DrawerLayout
 *
 * @param drawerLayout DrawerLayout
 * @param navView      NavigationView
 */
private void _initDrawerLayout(DrawerLayout drawerLayout, NavigationView navView) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
    localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
    //将侧边栏顶部延伸至status bar
    drawerLayout.setFitsSystemWindows(true);
    //将主页面顶部延伸至status bar
    drawerLayout.setClipToPadding(false);
  }
  drawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
    @Override
    public void onDrawerClosed(View drawerView) {
      mHandler.sendEmptyMessage(mItemId);
    }
  });
  navView.setNavigationItemSelectedListener(this);
}

代码示例来源:origin: iammert/MaterialIntroView

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_toolbar);
  final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  //User toolbar to access the views
  ImageView ivSearch = (ImageView) toolbar.findViewById(R.id.ivToolbarSearch);
  mIvShare = (ImageView) toolbar.findViewById(R.id.ivToolbarShare);
  mIvAbout = (ImageView) toolbar.findViewById(R.id.ivToolbarAbout);
  DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  drawer.setDrawerListener(toggle);
  toggle.syncState();
  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);
  //show the intro view
  showIntro(ivSearch, MENU_SEARCH_ID_TAG, getString(R.string.guide_setup_profile), FocusGravity.CENTER);
}

代码示例来源:origin: fython/MaterialStepperView

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  ActionBar actionBar = getSupportActionBar();
  assert actionBar != null;
  actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
  actionBar.setDisplayHomeAsUpEnabled(true);
  mDrawerLayout = findViewById(R.id.drawer_layout);
  mNavigationView = findViewById(R.id.navigation_view);
  mNavigationView.setNavigationItemSelectedListener(this);
  if (savedInstanceState == null) {
    replaceFragment(mVerticalStepperDemoFragment);
  }
}

代码示例来源:origin: mancj/MaterialSearchBar

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);
  searchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
  searchBar.setOnSearchActionListener(this);
  searchBar.inflateMenu(R.menu.main);
  searchBar.setText("Hello World!");
  Log.d("LOG_TAG", getClass().getSimpleName() + ": text " + searchBar.getText());
  searchBar.setCardViewElevation(10);
  searchBar.addTextChangeListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    }
    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
      Log.d("LOG_TAG", getClass().getSimpleName() + " text changed " + searchBar.getText());
    }
    @Override
    public void afterTextChanged(Editable editable) {
    }
  });
}

代码示例来源:origin: pockethub/PocketHub

drawerLayout.setDrawerListener(actionBarDrawerToggle);
navigationView.setNavigationItemSelectedListener(this);

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mFragmentNavigator = new FragmentNavigator(getSupportFragmentManager(), new MainFragmentAdapter(), R.id.container);
  mFragmentNavigator.setDefaultPosition(DEFAULT_POSITION);
  mFragmentNavigator.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
  NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView);
  navigationView.setNavigationItemSelectedListener(this);
  navigationView.setCheckedItem(IDS.get(DEFAULT_POSITION));
  mFragmentNavigator.showFragment(mFragmentNavigator.getCurrentPosition());
}

代码示例来源:origin: JohnPersano/SuperToasts

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
  final ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(
      this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
    @Override
    public void onDrawerSlide(View drawerView, float slideOffset) {
      // Stop animating the navigation icon
      super.onDrawerSlide(drawerView, 0);
    }
  };
  drawerLayout.addDrawerListener(actionBarDrawerToggle);
  actionBarDrawerToggle.syncState();
  final NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
  navigationView.setNavigationItemSelectedListener(this);
  navigationView.setCheckedItem(R.id.navigation_drawer_supertoast);
  // setCheckedItem() does not actually call the associated listener
  if (savedInstanceState == null) this.onNavigationItemSelected(navigationView.getMenu().getItem(0));
}

代码示例来源:origin: iMeiji/Toutiao

nav_view.setNavigationItemSelectedListener(this);

代码示例来源:origin: seven332/EhViewer

mNavView.setNavigationItemSelectedListener(this);

相关文章