导航抽屉图标没有显示使用appcompat v7

时间:2015-06-09 18:32:17

标签: android navigation-drawer appcompat-v7-r22.1

style.xml

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <item name="android:homeAsUpIndicator">@drawable/ic_back</item>
        <item name="homeAsUpIndicator">@drawable/ic_back</item>
    </style>

MainActivity.java

ActionBar actionBar = getSupportActionBar();

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
        actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
        View actionBarView = inflator.inflate(R.layout.custom_title, null);

actionBar.setCustomView(actionBarView);


        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.ic_action_nav_menu, //nav menu toggle icon
                R.string.app_name, // nav drawer open - description for accessibility
                R.string.app_name // nav drawer close - description for accessibility
        ) {
            public void onDrawerClosed(View view) {
                tvTitle.setText(mTitle);
                //getActionBar().setTitle(mTitle);
                // calling onPrepareOptionsMenu() to show action bar icons
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                tvTitle.setText(mDrawerTitle);
                //getActionBar().setTitle(mDrawerTitle);
                // calling onPrepareOptionsMenu() to hide action bar icons
                invalidateOptionsMenu();
            }
        };

enter image description here

你可以在上面的图像中看到,在黑色圆圈中我想要显示3行图像而不是后面的符号图像。

2 个答案:

答案 0 :(得分:2)

使用android.support.v7而不是android.support.v4如下:

import android.support.v7.app.ActionBarDrawerToggle;

并将mDrawerToggle更改为以下内容:

 mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.string.app_name, // nav drawer open - description for accessibility
            R.string.app_name // nav drawer close - description for accessibility
    )...

添加以下代码:

actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);

// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(new Runnable() {
     @Override
     public void run() {
         mDrawerToggle.syncState();
     }
});

答案 1 :(得分:0)

更改包导入android.support.v4.app.ActionBarDrawerToggle;至 import android.support.v7.app.ActionBarDrawerToggle;

mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout,R.string.app_name,R.string.app_); mDrawerlayout是对象DrawerLayout