如何有效地使用导航窗格 [英] How to effectively use navigation pane

查看:132
本文介绍了如何有效地使用导航窗格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

道歉这样一个基本的问题,但我怎么可以添加一个导航窗格中我的应用程序(一个从左侧滑入),我怎么可以把它启动其他活动的窗格内的按钮?

Apologies for such a basic question, but how can I add a navigation pane to my app (the one that slides in from the left) and how can I make it launch other Activities with buttons inside the pane?

推荐答案

我推荐材料设计的抽屉组件,像这样:的 http://mikepenz.github.io/MaterialDrawer/

I recommend a Material Design drawer component, like this: http://mikepenz.github.io/MaterialDrawer/

您可以开始新的活动使用意图

You can start new Activities using Intents.

如果您希望在用户点击一个按钮来启动一个新的活动,你必须创建在导航窗格中的 onItemClick 事件处理的意图:

If you want to start a new Activity when user clicks a button, you have to create the Intent in the navigation pane's onItemClick event handler:

@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem){
  if (position==0){ //user clicked first button in pane
    Intent intent = new Intent(this, FancyOtherActivity.class);
    startActivity(intent);
  }
  if (position==1){ //user clicked second button
    Intent intent = new Intent(this, GreatAnotherActivity.class);
    startActivity(intent);
  }

  ... //other buttons
}

这篇关于如何有效地使用导航窗格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆