當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。