【发布时间】:2016-11-14 17:14:22
【问题描述】:
我想在我的 Android 应用中使用选项实现一个抽屉菜单:
- 简介
- 设置
- 信息
对于 Drawermenu 的实现,有很多教程并且都非常清楚,但是我在我的 Reddit 应用程序中找不到与此类似的子菜单的任何内容:
点击“我的订阅”,我的订阅列表会展开。
这真的很难实现吗? 任何想法或建议表示赞赏
我的抽屉是这样设置的:
布局 XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#ffeeeeee"/>
</android.support.v4.widget.DrawerLayout>
MainActivity:
package com.example.simon.drawtest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends Activity {
private ListView mDrawerList;
private ArrayAdapter<String> mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
addDrawerItems();
}
private void addDrawerItems() {
String[] osArray = {"Profile", "Settings", "Info"};
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
}
}
谢谢大家!
【问题讨论】:
标签: android material-design submenu drawerlayout drawer