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


Java NavigationView类代码示例

本文整理汇总了Java中android.support.design.widget.NavigationView的典型用法代码示例。如果您正苦于以下问题:Java NavigationView类的具体用法?Java NavigationView怎么用?Java NavigationView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NavigationView类属于android.support.design.widget包,在下文中一共展示了NavigationView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initializeDrawer

import android.support.design.widget.NavigationView; //导入依赖的package包/类
private void initializeDrawer() {
	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.setNavigationItemSelectedListener(this);

	// Version
	TextView appVersion = (TextView) mNavigationView.getHeaderView(0).findViewById(R.id.app_version);
	appVersion.setText(getString(R.string.about_version,
			Utils.getVersionName(this),
			Integer.toString(Utils.getVersionCode(this))));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:MainActivity.java

示例2: 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

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

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).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.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
开发者ID:smallsilver,项目名称:VerticalWebView,代码行数:26,代码来源: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);
    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) {
        // on first time to display view for first navigation item based on the number
        navigationView.getMenu().getItem(0).setChecked(true);
        onNavigationItemSelected(navigationView.getMenu().getItem(0));
    }

}
 
开发者ID:anonymous-ME,项目名称:Automata,代码行数:26,代码来源:Main.java

示例5: initViews

import android.support.design.widget.NavigationView; //导入依赖的package包/类
private void initViews() {

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        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) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

    }
 
开发者ID:makezhao,项目名称:LianXiZhihu,代码行数:20,代码来源:MainActivity.java

示例6: onCreate

import android.support.design.widget.NavigationView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setDefaultValuesOfSettingsFirstTime();

    setContentView(R.layout.activity_hub);
    setupActionBar();

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.nav_view);

    setupNavigationView();

    if (savedInstanceState == null) {
        currentTag = tagHub;
        loadHomeFragment();
    } else {
        setToolbarTitle();
    }
}
 
开发者ID:android-gamecollection,项目名称:gamecollection,代码行数:22,代码来源:Hub.java

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

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).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.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

}
 
开发者ID:area101BD,项目名称:Hello-KUET,代码行数:27,代码来源:MainActivity.java

示例8: setupDrawerContent

import android.support.design.widget.NavigationView; //导入依赖的package包/类
private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(
            menuItem -> {
                switch (menuItem.getItemId()) {
                    case R.id.list_navigation_menu_item:
                        // Do nothing, we're already on that screen
                        break;
                    case R.id.statistics_navigation_menu_item:
                        Intent intent =
                                new Intent(TasksActivity.this, StatisticsActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                        break;
                    default:
                        break;
                }
                // Close the navigation drawer when an item is selected.
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();
                return true;
            });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:TasksActivity.java

示例9: setupDrawerContent

import android.support.design.widget.NavigationView; //导入依赖的package包/类
private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(
            menuItem -> {
                switch (menuItem.getItemId()) {
                    case R.id.list_navigation_menu_item:
                        Intent intent =
                                new Intent(StatisticsActivity.this, TasksActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                        break;
                    case R.id.statistics_navigation_menu_item:
                        // Do nothing, we're already on that screen
                        break;
                    default:
                        break;
                }
                // Close the navigation drawer when an item is selected.
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();
                return true;
            });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:StatisticsActivity.java

示例10: onCreate

import android.support.design.widget.NavigationView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dashboard);


        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(ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_COARSE_LOCATION)!=PackageManager.PERMISSION_GRANTED ) {
        checkLocationPermission();
        return;
    }
}
 
开发者ID:ayushghd,项目名称:iSPY,代码行数:23,代码来源:Dashboard.java

示例11: onListItemClick

import android.support.design.widget.NavigationView; //导入依赖的package包/类
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (((GlobalValues) getActivity().getApplication()).CanCreateVariable()) {
        Matrix m = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position);
        Matrix clone;
        clone = m.ExactClone("Copy_" + m.GetName());
        ((GlobalValues) getActivity().getApplication()).GetCompleteList().add(clone);
        ((GlobalValues) getActivity().getApplication()).matrixAdapter.notifyDataSetChanged();
        Toast.makeText(getContext(), "Saved as Copy_" + m.GetName(), Toast.LENGTH_SHORT).show();
        NavigationView view = (NavigationView) getActivity().findViewById(R.id.nav_view);
        view.setCheckedItem(R.id.Home);
        FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.MainContent, new MainActivityFragmentList());
        transaction.commit();
        ((MainActivity) getActivity()).SetMainActivity(true, getString(R.string.app_name), getString(R.string.MainSubtitle));
    } else {
        if (!((GlobalValues) getActivity().getApplication()).AdLoaded)
            Toast.makeText(getContext(), R.string.ToAddMoreTurnData, Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(getContext(), R.string.LimitExceeds, Toast.LENGTH_SHORT).show();
    }


}
 
开发者ID:coder3101,项目名称:Matrix-Calculator-for-Android,代码行数:25,代码来源:CloneFragment.java

示例12: onCreate

import android.support.design.widget.NavigationView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    setTitle("Default");

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = 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 = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
开发者ID:whitecloakph,项目名称:statelayout,代码行数:24,代码来源:MainActivity.java

示例13: drawToolbar

import android.support.design.widget.NavigationView; //导入依赖的package包/类
/**
 * Logic for toolbar
 */
protected void drawToolbar() {
    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.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    View header = navigationView.getHeaderView(0);
    TextView name = (TextView) header.findViewById(R.id.navBarUserName);

    //Get username info to display on header
    User currUser = CurrentUser.getInstance();
    name.setText(currUser.getDisplayName());

    ImageView photoView = (ImageView) header.findViewById(R.id.navBarUserImage);
    photoView.setTag(currUser.getPhotoUrl());
    new DownloadImageTask().execute(photoView);

}
 
开发者ID:CMPUT301F17T13,项目名称:cat-is-a-dog,代码行数:29,代码来源:BaseDrawerActivity.java

示例14: onCreate

import android.support.design.widget.NavigationView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_drawer);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).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.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
开发者ID:hushengjun,项目名称:FastAndroid,代码行数:26,代码来源:DrawerActivity.java

示例15: onCreate

import android.support.design.widget.NavigationView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceStatus) {
    Log.d(TAG, "onCreate()");
    super.onCreate(savedInstanceStatus);
    
    // Service connection
    atReceiver = new AtReceiver();
    
    // Drawer Layout
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    
    // Left Menu
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }
    setNavigationViewListner();
}
 
开发者ID:stefanonicolai,项目名称:AstronomyTourPadova,代码行数:19,代码来源:ReceiverActivity.java


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