本文整理了Java中android.support.design.widget.NavigationView
类的一些代码示例,展示了NavigationView
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NavigationView
类的具体详情如下:
包路径:android.support.design.widget.NavigationView
类名称:NavigationView
暂无
代码示例来源: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: TeamNewPipe/NewPipe
drawerItems.getMenu()
.add(R.id.menu_tabs_group, kioskId, 0, KioskTranslator.getTranslatedKioskName(ks, this))
.setIcon(KioskTranslator.getKioskIcons(ks, this));
drawerItems.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER, R.string.tab_subscriptions)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_channel));
drawerItems.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_FEED, ORDER, R.string.fragment_whats_new)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.rss));
drawerItems.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_BOOKMARKS, ORDER, R.string.tab_bookmarks)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_bookmark));
drawerItems.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_DOWNLOADS, ORDER, R.string.downloads)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.download));
drawerItems.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_HISTORY, ORDER, R.string.action_history)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.history));
drawerItems.getMenu()
.add(R.id.menu_options_about_group, ITEM_ID_SETTINGS, ORDER, R.string.settings)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.settings));
drawerItems.getMenu()
.add(R.id.menu_options_about_group, ITEM_ID_ABOUT, ORDER, R.string.tab_about)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.info));
drawerItems.setNavigationItemSelectedListener(this::drawerItemSelected);
setupDrawerHeader();
代码示例来源: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: 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: 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: naman14/Timber
public void run() {
navigationView.getMenu().findItem(R.id.nav_library).setChecked(true);
Fragment fragment = new MainFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, fragment).commitAllowingStateLoss();
}
};
代码示例来源:origin: xinghongfei/LookLook
nevigationId = SharePreferenceUtil.getNevigationItem(this);
if (nevigationId != -1) {
currentMenuItem = navView.getMenu().findItem(nevigationId);
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int[] iconcolor = new int[]{
Color.GRAY, Color.BLACK};
navView.setItemTextColor(new ColorStateList(state, color));
navView.setItemIconTintList(new ColorStateList(state, iconcolor));
MenuItem item = navView.getMenu().findItem(R.id.nav_theme);
mThemeSwitch = (SwitchCompat) MenuItemCompat.getActionView(item).findViewById(R.id.view_switch);
mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
代码示例来源:origin: ymback/NGA-CLIENT-VER-OPEN-SOURCE
private void initNavigationView(View rootView) {
NavigationView navigationView = rootView.findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this::onOptionsItemSelected);
MenuItem menuItem = navigationView.getMenu().findItem(R.id.menu_gun);
NavigationMenuView menuView = (NavigationMenuView) navigationView.getChildAt(0);
menuView.setVerticalScrollBarEnabled(false);
View actionView = getLayoutInflater().inflate(R.layout.nav_menu_action_view_gun, null);
menuItem.setActionView(actionView);
menuItem.expandActionView();
mReplyCountView = actionView.findViewById(R.id.reply_count);
mHeaderView = navigationView.getHeaderView(0).findViewById(R.id.viewFlipper);
updateHeaderView();
}
代码示例来源:origin: north2016/T-MVP
@Override
public void initUserInfo(User user) {
View mHeaderView = mViewBinding.nvMainNavigation.getHeaderView(0);
ImageView im_face = (ImageView) mHeaderView.findViewById(R.id.im_face);
TextView tv_name = (TextView) mHeaderView.findViewById(R.id.tv_name);
BindingUtils.loadRoundImg(im_face, user.face);
tv_name.setText(user.username);
}
代码示例来源:origin: seven332/EhViewer
public void setNavCheckedItem(@IdRes int resId) {
mNavCheckedItem = resId;
if (mNavView != null) {
if (resId == 0) {
mNavView.setCheckedItem(R.id.nav_stub);
} else {
mNavView.setCheckedItem(resId);
}
}
}
代码示例来源:origin: Michenux/YourAppIdea
protected void showPrimaryMenu() {
this.mHeaderArrowOpened = false;
this.getNavigationView().getMenu().clear();
this.getNavigationView().inflateMenu(R.menu.navigation_drawer_menu);
this.mPrimaryMenuDisplayed = true;
}
代码示例来源:origin: LRH1993/LiveCircle
/**
* 设置导航页信息
*/
private void setNavigationView() {
//NavigationView初始化
mAmNv.setItemIconTintList(null);
View headerView = mAmNv.getHeaderView(0);
mIv_photo = (ImageView) headerView.findViewById(R.id.iv_user_photo);
}
代码示例来源:origin: eneim/toro
navView.inflateHeaderView(R.layout.widget_space_4dp);
View header1 = navView.inflateHeaderView(R.layout.widget_hom_nav_header_1);
TextView header1Text = header1.findViewById(R.id.text_content);
header1Text.setText(getString(R.string.lib_info_version, BuildConfig.VERSION_NAME));
navView.inflateHeaderView(R.layout.widget_hom_nav_header_2);
navView.getHeaderView(3).<TextView>findViewById(R.id.text_content).setText(
Html.fromHtml(getString(R.string.lib_info_license)));
代码示例来源: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: naman14/Timber
navigationView.getMenu().findItem(R.id.nav_library).setIcon(R.drawable.library_music);
navigationView.getMenu().findItem(R.id.nav_playlists).setIcon(R.drawable.playlist_play);
navigationView.getMenu().findItem(R.id.nav_queue).setIcon(R.drawable.music_note);
navigationView.getMenu().findItem(R.id.nav_folders).setIcon(R.drawable.ic_folder_open_black_24dp);
navigationView.getMenu().findItem(R.id.nav_nowplaying).setIcon(R.drawable.bookmark_music);
navigationView.getMenu().findItem(R.id.nav_settings).setIcon(R.drawable.settings);
navigationView.getMenu().findItem(R.id.nav_about).setIcon(R.drawable.information);
navigationView.getMenu().findItem(R.id.nav_donate).setIcon(R.drawable.payment_black);
} else {
navigationView.getMenu().findItem(R.id.nav_library).setIcon(R.drawable.library_music_white);
navigationView.getMenu().findItem(R.id.nav_playlists).setIcon(R.drawable.playlist_play_white);
navigationView.getMenu().findItem(R.id.nav_queue).setIcon(R.drawable.music_note_white);
navigationView.getMenu().findItem(R.id.nav_folders).setIcon(R.drawable.ic_folder_open_white_24dp);
navigationView.getMenu().findItem(R.id.nav_nowplaying).setIcon(R.drawable.bookmark_music_white);
navigationView.getMenu().findItem(R.id.nav_settings).setIcon(R.drawable.settings_white);
navigationView.getMenu().findItem(R.id.nav_about).setIcon(R.drawable.information_white);
navigationView.getMenu().findItem(R.id.nav_donate).setIcon(R.drawable.payment_white);
navigationView.getMenu().removeItem(R.id.nav_donate);
代码示例来源:origin: TeamNewPipe/NewPipe
private void setupDrawerHeader() {
NavigationView navigationView = findViewById(R.id.navigation);
View hView = navigationView.getHeaderView(0);
serviceArrow = hView.findViewById(R.id.drawer_arrow);
headerServiceView = hView.findViewById(R.id.drawer_header_service_view);
Button action = hView.findViewById(R.id.drawer_header_action_button);
action.setOnClickListener(view -> {
toggleServices();
});
}
代码示例来源:origin: Rukey7/MvpApp
@Override
protected void updateViews(boolean isRefresh) {
mNavView.setCheckedItem(R.id.nav_news);
addFragment(R.id.fl_container, new NewsMainFragment(), "News");
}
代码示例来源: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: 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: JZ-Darkal/AndroidHttpCapture
navigationView.setNavigationItemSelectedListener(navigationItemListener);
navigationView.getMenu().getItem(0).setChecked(true);
内容来源于网络,如有侵权,请联系作者删除!