Material DesignDrawerLayout的旋转箭头的实现方式。

来源:互联网 发布:mysql添加数据 编辑:程序博客网 时间:2024/06/16 17:05

实际上,官方已经提供了实现方法,但是,有很多捞偏门的教程,也有很优秀的第三方。写出来,供还没找到的同学参考。


前提是:你对android.support.v7.widget.Toolbar已经有过了解了。

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. mMainBar = (Toolbar)this.findViewById(R.id.main_bar);  
  2. this.setSupportActionBar(mMainBar);  
  3. mDrawerLayout = (DrawerLayout)this.findViewById(R.id.main_drawer_layout);  
  4. mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mMainBar, R.string.app_name, R.string.hello_world);  
  5. mDrawerLayout.setDrawerListener(mToggle);  

以上是在onCreate里要做的事。注意:此时的ActionBarDrawerToggle不是v4包中的,而是android.support.v7.app.ActionBarDrawerToggle;这是关键。

这还没有结束,必须有以下代码才能实现旋转动画:

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. @Override  
  2.     protected void onPostCreate(Bundle savedInstanceState) {  
  3.         super.onPostCreate(savedInstanceState);  
  4.         // Sync the toggle state after onRestoreInstanceState has occurred.  
  5.         mToggle.syncState();  
  6.     }  
  7.   
  8.     @Override  
  9.     public void onConfigurationChanged(Configuration newConfig) {  
  10.         super.onConfigurationChanged(newConfig);  
  11.         // Pass any configuration change to the drawer toggls  
  12.         mToggle.onConfigurationChanged(newConfig);  
  13.     }  


0
0 0
原创粉丝点击