Android ActionBarDrawerToggle、DrawerLayout、ActionBar 结合
来源:互联网 发布:软考程序员教程 编辑:程序博客网 时间:2024/05/31 06:23
ActionBarDrawerToggle是一个开关,用于打开/关闭DrawerLayout抽屉
ActionBarDrawerToggle 提供了一个方便的方式来配合DrawerLayout和ActionBar,以实现推荐的抽屉功能。
即点击ActionBar的home按钮,即可弹出DrawerLayout抽屉。
在Activity中的两个回调函数中使用它:
onConfigurationChanged
onOptionsItemSelected
调用ActionBarDrawerToggle.syncState() 在Activity的onPostCreate()中;指示,ActionBarDrawerToggle与DrawerLayout的状态同步,并将ActionBarDrawerToggle中的drawer图标,设置为ActionBar的Home-Button的icon
关于DrawerLayout就不多说了,请移步这里 http://blog.csdn.net/jjwwmlp456/article/details/38682637
在这个官方的例子中,已经实现了本文所要讲述的内容。
整体的效果呢,需要支持ActionBar,support-v7包的 compat中有 ActionBarActivity可继承, 3.0以后也可以用主题的方式直接使用。不多说了
几个主要的函数调用
ActionBarDrawerToggle mDrawerToggle;DrawerLayout mDrawerLayout;void init() {mDrawerLayout.setDrawerListener(new MyDrawerListener());//设置drawer的开关监听mDrawerToggle = new ActionBarDrawerToggle(activity, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);}/** activity创建完成后 */@Overrideprotected void onPostCreate(Bundle savedInstanceState) {super.onPostCreate(savedInstanceState);mDrawerToggle.syncState();//该方法会自动和actionBar关联, 将开关的图片显示在了action上,如果不设置,也可以有抽屉的效果,不过是默认的图标}/** 菜单键点击的事件处理 */@Overridepublic boolean onOptionsItemSelected(MenuItem item) {return mDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);}/** 设备配置改变时 */@Overridepublic void onConfigurationChanged(Configuration newConfig) {super.onConfigurationChanged(newConfig);mDrawerToggle.onConfigurationChanged(newConfig);}/** drawer的监听 */private class MyDrawerListener implements DrawerLayout.DrawerListener {@Overridepublic void onDrawerOpened(View drawerView) {// 打开drawermDrawerToggle.onDrawerOpened(drawerView);//开关状态改为opened}@Overridepublic void onDrawerClosed(View drawerView) {// 关闭drawermDrawerToggle.onDrawerClosed(drawerView);//开关状态改为closed}@Overridepublic void onDrawerSlide(View drawerView, float slideOffset) {// drawer滑动的回调mDrawerToggle.onDrawerSlide(drawerView, slideOffset);}@Overridepublic void onDrawerStateChanged(int newState) {// drawer状态改变的回调mDrawerToggle.onDrawerStateChanged(newState);}}
9 0
- Android ActionBarDrawerToggle、DrawerLayout、ActionBar 结合
- Android ActionBarDrawerToggle、DrawerLayout、ActionBar 结合
- Android ActionBarDrawerToggle、DrawerLayout、ActionBar 结合
- Android ActionBarDrawerToggle、DrawerLayout、ActionBar 结合
- Android中ActionBarDrawerToggle、DrawerLayout、ActionBar 使用说明
- 谷歌电子市场-ActionBarDrawerToggle、DrawerLayout、ActionBar
- ActionBar、Drawerlayout、ActionBarDrawerToggle实现抽屉效果
- DrawerLayout抽屉和ActionBar结合
- ActionBarDrawerToggle与DrawerLayout
- DrawerLayout与ActionBarDrawerToggle使用
- 简单DrawerLayout与ActionBar的结合使用
- SlidingPaneLayout,DrawerLayout,ActionBar,NavigationView 详解 <三> NavigationView,DrawerLayout 结合ActionB
- android actionbar+drawerLayout相关联
- ActionBar简单使用——添加搜索按钮;让不同的Activity上显示不同的ActionBar;添加Tab标签;实现DrawerLayout并用ActionBarDrawerToggle控制
- Android开发之ActionBar与DrawerLayout
- 用Android自带的DrawerLayout和ActionBarDrawerToggle实现侧滑效果
- ActionBarDrawerToggle和ToolBar结合使用
- Android中级:ActionBar + DrawerLayout实现侧滑菜单
- 第十二周项目4-银行系统任务4
- 日间比较
- sqlite日期函数
- Plug-in com.android.ide.eclipse.adt was unable to load class
- swig安装搭建与测试
- Android ActionBarDrawerToggle、DrawerLayout、ActionBar 结合
- 第12周项目3.5 输出整数所对应的二进制数
- 第十二周项目三(3)递归法求两个数的最大公约数
- Could not load the "logo.png" image referenced from a nib in the bundle with identifier
- 虚拟摄像头驱动程序框架分析
- VC++工程中使用C文件
- 谈谈Objective-C的警告
- 用 Python 解回文数的个数
- Android基础:十八般武器之TabHost