当前位置: 首页>>代码示例>>Java>>正文


Java NavigationView.setCheckedItem方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:MainActivity.java

示例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 );
}
 
开发者ID:chrisqz95,项目名称:couch-potatoes,代码行数:26,代码来源:ChatRoomActivity.java

示例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;
    }
}
 
开发者ID:an-garcia,项目名称:MovieGuide,代码行数:27,代码来源:MainActivity.java

示例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);

}
 
开发者ID:gaelthas,项目名称:Palatta,代码行数:24,代码来源:MainActivity.java

示例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);

}
 
开发者ID:EdwardAlexis,项目名称:Sistema-de-Comercializacion-Negocios-Jhordan,代码行数:21,代码来源:Inicio.java

示例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);

}
 
开发者ID:EdwardAlexis,项目名称:Sistema-de-Comercializacion-Negocios-Jhordan,代码行数:22,代码来源:Ventas.java

示例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);
}
 
开发者ID:EdwardAlexis,项目名称:Sistema-de-Comercializacion-Negocios-Jhordan,代码行数:24,代码来源:Reportes.java

示例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 );
}
 
开发者ID:chrisqz95,项目名称:couch-potatoes,代码行数:26,代码来源:MatchingActivity.java

示例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");
}
 
开发者ID:concretesolutions,项目名称:treinamentos-android,代码行数:36,代码来源:MainActivity.java

示例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);
        }
    });
}
 
开发者ID:WillFlower,项目名称:BluetoothCtrl,代码行数:40,代码来源:MainActivity.java

示例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();
        }
    });

}
 
开发者ID:Sayi,项目名称:RestClient,代码行数:37,代码来源:HomeActivity.java

示例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();
}
 
开发者ID:peterdestasio,项目名称:Geoclick,代码行数:13,代码来源:MainActivity.java

示例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);
}
 
开发者ID:brandall76,项目名称:API-Example-App,代码行数:12,代码来源:MainActivity.java

示例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);
}
 
开发者ID:Shuanghua,项目名称:LikeGank,代码行数:14,代码来源:MainActivity.java

示例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);
    }
}
 
开发者ID:roshakorost,项目名称:Phial,代码行数:29,代码来源:HomeActivity.java


注:本文中的android.support.design.widget.NavigationView.setCheckedItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。