1. 布局
<android.support.v4.widget.DrawerLayout android:id="@+id/i_drawerLayout" android:layout_width="match_parent" android:layout_height="match_parent"> //主界面 <LinearLayout android:layout_width="match_parent" android:background="#f0f" android:layout_height="match_parent"> </LinearLayout> //侧滑菜单 <LinearLayout android:background="#00f" android:gravity="start" android:layout_gravity="left" android:layout_width="match_parent" android:layout_height="match_parent"> </LinearLayout> </android.support.v4.widget.DrawerLayout>
2. 改为该界面继承Activity
MainActivity extends Activity
3. 改变主题
<style name="AppTheme" parent="android:Theme.Material"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style>
4. 写主要逻辑代码
public class MainActivity extends Activity { DrawerLayout drawerLayout; ActionBarDrawerToggle drawerToggle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawerLayout= (DrawerLayout) findViewById(R.id.i_drawerLayout); drawerToggle=new ActionBarDrawerToggle(this,drawerLayout,0,0); drawerLayout.setDrawerListener(drawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); drawerToggle.syncState(); } @Override public boolean onOptionsItemSelected(MenuItem item) { drawerToggle.onOptionsItemSelected(item); return super.onOptionsItemSelected(item); } @Override public void onConfigurationChanged(Configuration newConfig) { drawerToggle.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig); } }
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦