如何有效地使用导航窗格有效地、窗格

2023-09-12 05:48:24 作者:比较忧伤的女孩专属

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

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
}