我正在尝试在应该支持Android 4。+
的应用程序中使用NavigationDrawer因此我使用的是Native Activity,ActionBar和Fragment类(不是支持和AppCompat类)。
除了抽屉打开时导航抽屉图标(种类的汉堡)没有动画到左边的动画之外,一切似乎都很好。
NavigationDrawer是否要求我使用AppCompat库和相应的ActionBar支持?
答案 0 :(得分:1)
不,NavigationDrawer不要求您使用AppCompat员工。检查听众是否是最有可能导致问题的原因,或者发布代码供我们检查。
我不确定链接是否正确,但在某些Google I / O 2013 Talk中,他们建议使用支持库,即使您定位API 14+,原因很简单,错误修复会更快地传递给您随着支持库发布然后与框架发布。出于这个原因,我将应用程序切换为使用支持库组件。
P.S。我认为这是在这次谈话中http://www.youtube.com/watch?v=qlrKh-L4bqU
答案 1 :(得分:0)
如果要将DrawerLayout
用于NavigationDrawer,则必须使用支持库v4。
http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
或者您忘记了ActionBarDrawerToggle
public void onCreate(Bundle savedInstanceState) {
...
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}