如何将动画设置为滑动菜单图标

时间:2014-07-06 15:07:54

标签: android actionbarsherlock slidingmenu android-sliding

我正在使用jfeinstein10的滑动菜单,我可以设置此处给出的导航抽屉图标

http://romannurik.github.io/AndroidAssetStudio/icons-nav-drawer-indicator.html

现在我想知道如何为它设置动画,就像当我拖动滑动列表时,它应该显示小时刻效果,就像我们在Play商店应用中看到的那样。

我正在使用ABS库进行操作栏

1 个答案:

答案 0 :(得分:0)

对于导航抽屉的应用程序图标控件,请在MainActivity上添加新属性

ActionBarDrawerToggle mDrawerToggle;

在values / string /

中添加打开和关闭描述
<string name="drawer_open">Open navigation drawer</string>
<string name="drawer_close">Close navigation drawer</string>

在MainActivity oncreate中添加应用图标控制代码

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
    this,
    mDrawerLayout,
    R.drawable.ic_drawer, 
    R.string.drawer_open, 
    R.string.drawer_close 
    ) {

/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
    super.onDrawerClosed(view);
    getActionBar().setTitle(mTitle);
}

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
    super.onDrawerOpened(drawerView);
    getActionBar().setTitle(mDrawerTitle);
}
};

mDrawerLayout.setDrawerListener(mDrawerToggle);

getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);

添加onOptionsItemSelected()方法。这确实需要使应用程序图标成为导航抽屉的切换。

@Override
public boolean onOptionsItemSelected(MenuItem item) {

if (mDrawerToggle.onOptionsItemSelected(item)) {
   return true;
}

return super.onOptionsItemSelected(item);
}

最后,在onPostCreate()方法中。这确实需要在应用程序图标

之前更改向上插入符号图标
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}