main_layout
<android.support.v4.widget.DrawerLayout android:id="@+id/dl_root" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical"> <FrameLayout android:layout_height="0dp" android:layout_width="match_parent" android:id="@+id/fram_layout" android:layout_weight="9"/> <RadioGroup android:layout_height="0dp" android:layout_width="match_parent" android:id="@+id/radio_group" android:orientation="horizontal" android:layout_weight="1"> <RadioButton android:layout_height="match_parent" android:layout_width="0dp" android:id="@+id/rb_first" android:layout_weight="1" android:button="@null" android:gravity="center" android:text="首页"/> <RadioButton android:layout_height="match_parent" android:layout_width="0dp" android:id="@+id/rb_xigua" android:layout_weight="1" android:button="@null" android:gravity="center" android:text="西瓜视频"/> </RadioGroup> </LinearLayout> <LinearLayout android:layout_height="match_parent" android:layout_width="240dp" android:orientation="vertical" android:layout_gravity="start" android:background="#595353"> <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center_horizontal" android:src="@mipmap/ic_launcher_round"/> <TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:gravity="center_horizontal" android:text="网易小王子"/> <ListView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/list_drawer"/> </LinearLayout> </android.support.v4.widget.DrawerLayout>
-------MainActivity
//初始化控件 dl_root = findViewById(R.id.dl_root); list_drawer = findViewById(R.id.list_drawer); fram_layout = findViewById(R.id.fram_layout); radio_group = findViewById(R.id.radio_group); list = new ArrayList<>(); list.add("我的音乐"); list.add("我的会员"); list.add("我的网盘"); list.add("我的关注"); list_drawer.setAdapter(new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,list)); dl_root.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); //intiActionBar();
private void intiActionBar() { ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); mToggle = new ActionBarDrawerToggle(this, dl_root, R.string.open, R.string.close); mToggle.syncState(); dl_root.addDrawerListener(mToggle); } @Override public boolean onOptionsItemSelected(MenuItem item) { if(mToggle.onOptionsItemSelected(item)){ return true; } return super.onOptionsItemSelected(item); }