我在我的 Android 应用程序中使用 Navigation Drawer,它工作正常。
我想为打开和关闭导航抽屉添加一些动画。
动画:
1.Opening-Navigation Drawer显示箭头,隐藏汉堡。
2.Closing-Again Show the Hamburger,隐藏箭头。
而打开和关闭它应该是旋转。我尝试了一些代码它不起作用。
请任何人帮助我做到这一点。
样式.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>
我试过这个, 我提到的链接
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
//for Navigation Bar
DrawerLayout drawerLayout;
ListView listView;
String[] drawerlist;
ActionBarDrawerToggle drawerListener;
private MyAdapter4 myAdapter4;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.alerts);
//navigation initialize
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
listView = (ListView) findViewById(R.id.drawerList);
drawerlist = getResources().getStringArray(R.array.drawerlist);
myAdapter4 = new MyAdapter4(this);
listView.setAdapter(myAdapter4);
//for navigation click
listView.setOnItemClickListener(new DrawerItemClickListener());
//Navigation Bar starts
drawerListener = new ActionBarDrawerToggle
(this, drawerLayout, R.drawable.ic_drawer,
R.string.drawer_open, R.string.drawer_close)
{
public void onDrawerClosed(View drawerView)
{
super.onDrawerClosed(drawerView);
}
public void onDrawerOpened(View drawerView)
{
super.onDrawerOpened(drawerView);
}
};
drawerLayout.setDrawerListener(drawerListener);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
我的导航抽屉代码