导航抽屉切换在所有设备上都不可见

时间:2013-12-02 09:20:35

标签: android navigation-drawer

我已经像这样实现了我的NavigationDrawer

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    actionBarDrawerToggle = new ActionBarDrawerToggle(
            this,                                     /* host Activity */
            drawerLayout,                             /* DrawerLayout object */
            R.drawable.ic_drawer,                     /* nav drawer icon to replace 'Up' caret */
            R.string.navigation_drawer_open,          /* "open drawer" description */
            R.string.navigation_drawer_close          /* "close drawer" description */
    );

    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    getActionBar().setDisplayHomeAsUpEnabled(true);

一开始它似乎完美无缺(Nexus 5)。 然后我在Sony LT25i和Nexus S上测试了应用程序。在这些设备上没有显示图标...... 我认为它可能是显示尺寸的东西,因为nexus 5是其中最大的,但我不知道如何解决这个问题。

所有设备均为Android 4.0 +

1 个答案:

答案 0 :(得分:0)

抱歉使用SherlockNavigainDrawer lib

太晚了

ActionBarDrawerToggle 替换为 SherlockActionBarDrawerToggle

下面给出了这个例子

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

        public void onDrawerClosed(View view) {
            // your code
        }

        public void onDrawerOpened(View drawerView) {
            // your code
        }
    };
drawerLayout.setDrawerListener(mDrawerToggle);
 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
// ----------------------------------------------------------------------
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    mDrawerToggle.syncState();
}

// ----------------------------------------------------------------------
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    mDrawerToggle.onConfigurationChanged(newConfig);
}

// ----------------------------------------------------------------------
@Override
public boolean onOptionsItemSelected(MenuItem item) {

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

    return super.onOptionsItemSelected(item);
}

希望这会对你有所帮助