-1

我最近创建了一个实现侧边菜单的应用程序。菜单实际上是通过点击左上角出现的,但我想实现一个滑动动作(如 facebook 应用程序)来调用它。

以下是部分代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    Eula.show(this);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    icon = (ImageView) findViewById(android.R.id.icon);
    sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view);
    sideNavigationView.setMenuItems(R.menu.side_navigation_menu);
    sideNavigationView.setMenuClickCallback(this);

    if (getIntent().hasExtra(EXTRA_TITLE)) {
        String title = getIntent().getStringExtra(EXTRA_TITLE);
        int resId = getIntent().getIntExtra(EXTRA_RESOURCE_ID, 0);
        setTitle(title);
        icon.setImageResource(resId);
    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        sideNavigationView.toggleMenu();
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

@Override
public void onSideNavigationItemClick(int itemId) {
    switch (itemId) {
    case R.id.side_navigation_menu_item1:
        Intent moppen = new Intent(this, page1.class);     
        startActivity(moppen);
        break;
    case R.id.side_navigation_menu_item2:
        Intent page2 = new Intent(this, page2.class);     
        startActivity(page2);
        break;
    case R.id.side_navigation_menu_item3:
        Intent plaatjes = new Intent(this, page3.class);     
        startActivity(plaatjes);
        break;
    case R.id.side_navigation_menu_item4:
        Intent special = new Intent(this, page4.class);     
        startActivity(special);
        break;
    case R.id.side_navigation_menu_item5:
        Intent over = new Intent(this, page5.class);     
        startActivity(over);
        break;
    default:
        return;
    }
    finish();
}
4

1 回答 1

0

使用这个库https://github.com/jfeinstein10/SlidingMenu,然后在 oncreate()

 SlidingMenu menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
 menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setMenu(R.layout.menu);

然后在菜单中。

menu.toggle();
于 2013-05-22T07:20:14.280 回答