本文整理汇总了Java中android.support.design.widget.NavigationView.setCheckedItem方法的典型用法代码示例。如果您正苦于以下问题:Java NavigationView.setCheckedItem方法的具体用法?Java NavigationView.setCheckedItem怎么用?Java NavigationView.setCheckedItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.widget.NavigationView
的用法示例。
在下文中一共展示了NavigationView.setCheckedItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
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.nav_view);
navigationView.setNavigationItemSelectedListener(this);
if (savedInstanceState == null) {
int selectedItem = PreferenceManager.getDefaultSharedPreferences(this).getInt(
KEY_SELECTED_NAVDRAWER_ITEM_ID,
INITIAL_NAVDRAWER_ITEM_ID);
handleNavigationItemClick(selectedItem);
navigationView.setCheckedItem(selectedItem);
}
}
示例2: setSideBarDrawer
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
private void setSideBarDrawer( DrawerLayout mDrawer, NavigationView navView,
Toolbar toolbar, DBHelper helper) {
// enables toggle button on toolbar to open the sidebar
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
mDrawer.addDrawerListener(toggle);
toggle.syncState();
// set up side navigation bar layout
navView.setNavigationItemSelectedListener(this);
// Want to display icons in original color scheme
navView.setItemIconTintList(null);
// highlight the current location
navView.setCheckedItem(R.id.nav_matches);
// sets up TextViews in sidebar to display the user's name and email
sidebarUserName = (android.widget.TextView) navView.getHeaderView(0)
.findViewById(R.id.sidebar_username);
sidebarUserEmail = (android.widget.TextView) navView.getHeaderView(0)
.findViewById(R.id.sidebar_user_email);
setSideBarText( sidebarUserName, sidebarUserEmail, helper );
}
示例3: assignCheckedItem
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
public void assignCheckedItem(String page){
// set selected
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
switch (page){
case HOME:
navigationView.setCheckedItem(R.id.nav_home);
break;
case MOVIES:
navigationView.setCheckedItem(R.id.nav_movies);
break;
case TV_SHOWS:
navigationView.setCheckedItem(R.id.nav_tv_shows);
break;
case PEOPLE:
navigationView.setCheckedItem(R.id.nav_people);
break;
case FAVORITES:
navigationView.setCheckedItem(R.id.nav_favorites);
break;
case DISCOVER:
case DISCOVER_RESULT:
navigationView.setCheckedItem(R.id.nav_discover);
break;
}
}
示例4: onCreate
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mFragments = new ArrayList<>();
mFragments.add(new PaletteFragment());
mFragments.add(new ColorsFragment());
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawer.addDrawerListener(toggle);
toggle.syncState();
mNavigationView = (NavigationView) findViewById(R.id.nav_view);
mNavigationView.setCheckedItem(R.id.nav_palette);
mNavigationView.setNavigationItemSelectedListener(this);
}
示例5: onCreate
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inicio_navigation_drawer);
this.setTitle(R.string.nav_inicio);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_inicio);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.inicio_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.inicio_nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_inicio);
}
示例6: onCreate
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ventas_navigation_drawer);
this.setTitle(R.string.nav_ventas);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_ventas);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.ventas_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.ventas_nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_ventas);
}
示例7: onCreate
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reportes_navigation_drawer);
this.setTitle(R.string.nav_reportes);
/*menu*/
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_reportes);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.reportes_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.reportes_nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_reportes);
}
示例8: setSideBarDrawer
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
private void setSideBarDrawer( DrawerLayout mDrawer, NavigationView navView,
Toolbar toolbar, DBHelper helper) {
// enables toggle button on toolbar to open the sidebar
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
mDrawer.addDrawerListener(toggle);
toggle.syncState();
// set up side navigation bar layout
navView.setNavigationItemSelectedListener(this);
// Want to display icons in original color scheme
navView.setItemIconTintList(null);
// highlight the current location
navView.setCheckedItem(R.id.nav_matches);
// sets up TextViews in sidebar to display the user's name and email
sidebarUserName = (android.widget.TextView) navView.getHeaderView(0)
.findViewById(R.id.sidebar_username);
sidebarUserEmail = navView.getHeaderView(0)
.findViewById(R.id.sidebar_user_email);
setSideBarText( sidebarUserName, sidebarUserEmail, helper );
}
示例9: onCreate
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
fm = getSupportFragmentManager();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Fragment fragment = fm.findFragmentById(R.id.content);
if (fragment != null && fragment instanceof AnimationFragment) {
((AnimationFragment) fragment).runAnimation();
} else {
Toast.makeText(MainActivity.this, "fragment não encontrado", Toast.LENGTH_SHORT).show();
}
}
});
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.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.view_scale);
setFragment(ViewScaleFragment.newInstance());
setTitle("Scale ViewAnimation");
}
示例10: initView
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
private void initView() {
mProgressBar = findViewById(R.id.progressBar);
mTextViewReceive = (TextView) findViewById(R.id.textViewReceive);
mEditTextSend = (EditText) findViewById(R.id.etSend);
mButtonSend = (Button) findViewById(R.id.buttonSend);
mButtonSend.setOnClickListener(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navView = (NavigationView) findViewById(R.id.nav_view);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
}
navView.setCheckedItem(R.id.nav_call);
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
mDrawerLayout.closeDrawers();
return true;
}
});
FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mBluetoothLeService != null &&
mConnectionState.equals(BluetoothLeService.ACTION_GATT_CONNECTED)) {
mBluetoothLeService.disconnect();
}
Intent intent = new Intent(MainActivity.this, BluetoothScanActivity.class);
startActivityForResult(intent, REQUEST_CONNECT);
}
});
}
示例11: onCreate
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
actionBar = getSupportActionBar();
actionBar.setHomeAsUpIndicator(R.drawable.ic_rest);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.app_name);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setItemIconTintList(null);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_rest);
mViewPager = (AdvancedViewPager) findViewById(R.id.pager);
PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(pagerAdapter);
mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setTitle(navigationView.getMenu().getItem(position).getTitle());
actionBar.setHomeAsUpIndicator(R.drawable.ic_rest);
navigationView.getMenu().getItem(position).setChecked(true);
invalidateOptionsMenu();
}
});
}
示例12: onStart
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onStart() {
super.onStart();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_mapview);
MapViewFragment mapViewFragment = new MapViewFragment();
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction().replace(R.id.root_layout, mapViewFragment, mapViewFragment.getTag()).commit();
}
示例13: setupNavigation
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
/**
* Self explanatory utility
*/
private void setupNavigation() {
Log.i(CLS_NAME, "setupNavigation");
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_basic);
navigationView.getMenu().getItem(INDEX_FRAGMENT_DEMO_BASIC).setChecked(true);
}
示例14: initNavigationView
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
private void initNavigationView() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
drawer, mToolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView mNavigationView = findViewById(R.id.nav_view);
mNavigationView.setNavigationItemSelectedListener(this);
mNavigationView.setItemIconTintList(null);
mNavigationView.setCheckedItem(R.id.nav_home);
}
示例15: onCreate
import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
sharedElements = new ArrayList<>();
super.onCreate(savedInstanceState);
Phial.setKey("currentActivity", getClass().getSimpleName());
setContentView(R.layout.activity_home);
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout);
final ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
drawer,
toolbar,
R.string.drawer_open,
R.string.drawer_close
);
drawer.addDrawerListener(toggle);
toggle.syncState();
final NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
if (savedInstanceState == null) {
showFragmentById(DEFAULT_FRAGMENT);
navigationView.setCheckedItem(DEFAULT_FRAGMENT);
}
}