本文整理了Java中android.support.design.widget.NavigationView.setCheckedItem()
方法的一些代码示例,展示了NavigationView.setCheckedItem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NavigationView.setCheckedItem()
方法的具体详情如下:
包路径:android.support.design.widget.NavigationView
类名称:NavigationView
方法名:setCheckedItem
暂无
代码示例来源: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: Rukey7/MvpApp
@Override
protected void updateViews(boolean isRefresh) {
mNavView.setCheckedItem(R.id.nav_news);
addFragment(R.id.fl_container, new NewsMainFragment(), "News");
}
代码示例来源: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: Rukey7/MvpApp
@Override
public void onBackPressed() {
// 获取堆栈里有几个
final int stackEntryCount = getSupportFragmentManager().getBackStackEntryCount();
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else if (stackEntryCount == 1) {
// 如果剩一个说明在主页,提示按两次退出app
_exit();
} else {
// 获取上一个堆栈中保存的是哪个页面,根据name来设置导航项的选中状态
final String tagName = getSupportFragmentManager().getBackStackEntryAt(stackEntryCount - 2).getName();
int index = mSparseTags.indexOfValue(tagName);
mNavView.setCheckedItem(mSparseTags.keyAt(index));
super.onBackPressed();
}
}
代码示例来源: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: guolindev/booksource
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
navView.setCheckedItem(R.id.nav_call);
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
代码示例来源:origin: WangDaYeeeeee/Mysplash
@Override
public void setCheckedItem(int id) {
if (id == R.id.action_home
|| id == R.id.action_following
|| id == R.id.action_multi_filter
|| id == R.id.action_selected) {
nav.setCheckedItem(id);
}
}
}
代码示例来源:origin: materialos/android-icon-pack
@Override
public void run() {
mNavView.setCheckedItem(selectedId);
}
});
代码示例来源:origin: NASAWorldWind/WorldWindAndroid
@Override
protected void onResume() {
super.onResume();
// Update the menu by highlighting the last selected menu item
this.navigationView.setCheckedItem(selectedItemId);
// Use this Activity's Handler to periodically print the FrameMetrics.
this.handler.sendEmptyMessageDelayed(PRINT_METRICS, PRINT_METRICS_DELAY);
}
代码示例来源:origin: TongmingWu/Manga
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (viewPager.getCurrentItem()) {
case 0:
nav.setCheckedItem(R.id.menu_collected);
break;
case 1:
default:
nav.setCheckedItem(R.id.menu_index);
break;
}
initUser();
}
代码示例来源:origin: NASAWorldWind/WorldWindAndroid
@Override
protected void onResume() {
super.onResume();
// Update the menu by highlighting the last selected menu item
this.navigationView.setCheckedItem(selectedItemId);
// Use this Activity's Handler to periodically print the FrameMetrics.
this.handler.sendEmptyMessageDelayed(PRINT_METRICS, PRINT_METRICS_DELAY);
// Restore the navigator's camera state from previously saved session data
this.restoreNavigatorState();
}
代码示例来源:origin: TongmingWu/Manga
@Override
public void onTabSelected(TabLayout.Tab tab) {
selectedIcon(tab);
if (tab.getPosition() == 0) {
nav.setCheckedItem(R.id.menu_collected);
} else {
nav.setCheckedItem(R.id.menu_index);
}
viewPager.setCurrentItem(tab.getPosition());
}
代码示例来源:origin: huyongli/TigerVideo
private void init() {
BaseFragment fragment = FragmentFactory.createMainFragment(DataType.NET_EASY);
switchFragment(fragment);
mNavigationView.setCheckedItem(R.id.nav_net_easy);
mFragmentSparseArray.put(R.id.nav_net_easy, fragment);
}
代码示例来源:origin: ABTSoftware/SciChart.Android.Examples
@Override
public boolean onNavigationItemSelected(MenuItem item) {
String category = String.valueOf(item.getTitleCondensed());
navigationView.setCheckedItem(item.getItemId());
selectedPosition = categories.indexOf(category);
updateLoadExamples(selectedPosition);
tryCloseDrawer();
return true;
}
代码示例来源:origin: renyuneyun/Easer
@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
getSupportFragmentManager().popBackStack(0, 0); // The -1'st is the Outline. We rely on super.onBackPressed() to pop the 0th.
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setCheckedItem(R.id.nav_outline);
super.onBackPressed();
}
}
代码示例来源:origin: NASAWorldWind/WorldWindAndroid
protected void onCreateDrawer() {
// Add support for a Toolbar and set to act as the ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Add support for the navigation drawer full of examples
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
this.drawerToggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(this.drawerToggle);
this.drawerToggle.syncState();
this.navigationView = (NavigationView) findViewById(R.id.nav_view);
this.navigationView.setNavigationItemSelectedListener(this);
this.navigationView.setCheckedItem(selectedItemId);
}
代码示例来源:origin: NASAWorldWind/WorldWindAndroid
protected void onCreateDrawer() {
// Add support for a Toolbar and set to act as the ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Add support for the navigation drawer full of examples
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
this.drawerToggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(this.drawerToggle);
this.drawerToggle.syncState();
this.navigationView = (NavigationView) findViewById(R.id.nav_view);
this.navigationView.setNavigationItemSelectedListener(this);
this.navigationView.setCheckedItem(selectedItemId);
}
代码示例来源:origin: guanpj/JReadHub
@Override
public void initView() {
if (findFragment(MainFragment.class) == null) {
loadRootFragment(R.id.fl_container, MainFragment.newInstance());
}
mNavigationView.setCheckedItem(R.id.nav_home);
}
代码示例来源:origin: renyuneyun/Easer
@Override
public void onClick(View view) {
NavigationView navigationView = getActivity().findViewById(R.id.nav_view);
navigationView.setCheckedItem(R.id.nav_log);
//noinspection ConstantConditions
((MainActivity) getContext()).changeUIView(R.id.nav_log);
}
});
内容来源于网络,如有侵权,请联系作者删除!