本文整理汇总了Java中android.support.design.widget.NavigationView.OnNavigationItemSelectedListener类的典型用法代码示例。如果您正苦于以下问题:Java OnNavigationItemSelectedListener类的具体用法?Java OnNavigationItemSelectedListener怎么用?Java OnNavigationItemSelectedListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OnNavigationItemSelectedListener类属于android.support.design.widget.NavigationView包,在下文中一共展示了OnNavigationItemSelectedListener类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupDrawerContent
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
private void setupDrawerContent(NavigationView navigationView) {
navigationView.setNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
menuItem.setChecked(true);
mDrawerLayout.closeDrawers();
switch (menuItem.getItemId()) {
case R.id.navItem1:
Intent alarm = new Intent(AlarmClock.ACTION_SET_ALARM);
startActivity(alarm);
break;
case R.id.navItem2:
try {
export();
} catch (IOException e) {
e.printStackTrace();
}
break;
}
return false;
}
});
}
示例2: onCreateView
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_menu, container,
false);
//得到左侧的列表
NavigationView navigationView = (NavigationView) view.findViewById(R.id.vNavigation);
//设置监听
navigationView.setNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
String title = (String) menuItem.getTitle();
//Toast.makeText(getActivity(), "您点击了 " + title, Toast.LENGTH_SHORT).show();
switch (title) {
case "首页":
Toast.makeText(getActivity(), "这已经是首页了,你再点试试看?", Toast.LENGTH_SHORT).show();
break;
case "随手记":
Intent intent1 = new Intent(getActivity(), MemoActivity.class);
startActivity(intent1);
MainActivity.handler.sendEmptyMessage(1);//通知关闭左侧栏
break;
case "便签":
Intent intent2 = new Intent(getActivity(), AtyList.class);
startActivity(intent2);
MainActivity.handler.sendEmptyMessage(1);//通知关闭左侧栏
break;
case "天气":
Intent intent4 = new Intent(getActivity(), WeatherActivity.class);
startActivity(intent4);
MainActivity.handler.sendEmptyMessage(1);//通知关闭左侧栏
break;
case "关于":
Toast.makeText(getActivity(), "这里没什么东西~", Toast.LENGTH_LONG).show();
MainActivity.handler.sendEmptyMessage(1);//通知关闭左侧栏
break;
default:
break;
}
return false;
}
});
return setupReveal(view) ;
}
示例3: getParent
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
@Nullable private OnNavigationItemSelectedListener getParent() {
Activity activity = getActivity();
if (activity instanceof OnNavigationItemSelectedListener) {
return (OnNavigationItemSelectedListener) activity;
}
return null;
}
示例4: setupNavigationView
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
private void setupNavigationView(NavigationView view) {
view.setNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
if (mCurrentNavItem == menuItem.getItemId()) {
mDrawerLayout.closeDrawers();
return true;
}
switch (menuItem.getItemId()) {
case R.id.drawer_menu_library:
setFragment(new LibraryFragment());
break;
case R.id.drawer_menu_browser:
setFragment(new BrowserFragment());
break;
case R.id.drawer_menu_about:
setTitle(R.string.menu_about);
setFragment(new AboutFragment());
break;
}
mCurrentNavItem = menuItem.getItemId();
menuItem.setChecked(true);
mDrawerLayout.closeDrawers();
return true;
}
});
}
示例5: setNavigationItemSelectedListener
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
public void setNavigationItemSelectedListener(@Nullable OnNavigationItemSelectedListener listener) {
navigationView.setNavigationItemSelectedListener(listener);
}
示例6: attach
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; //导入依赖的package包/类
/**
* Attach the fragment to hold the drawer and toolbar
*
* @param parent a Activity that extends AppCompatActivity & OnNavigationItemSelectedListener
* @return {@link DrawerDelegate}
*/
public static <ParentActivity extends AppCompatActivity & OnNavigationItemSelectedListener> DrawerDelegate attach(
@Nullable ParentActivity parent) {
return attach(parent.getSupportFragmentManager());
}