本文整理汇总了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))));
}
示例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);
}
}
示例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);
}
示例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));
}
}
示例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);
}
示例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();
}
}
示例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);
}
示例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;
});
}
示例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;
});
}
示例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;
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}