android - 使用 appcompat v7 不显示抽屉导航图标

标签 android navigation-drawer android-appcompat

样式.xml

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

主 Activity .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 行图像而不是背面符号图像。

最佳答案

使用 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();
     }
});

关于android - 使用 appcompat v7 不显示抽屉导航图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30740055/

相关文章:

android - 在 Play 商店和设备上处理多个 DPI 的 Assets

android - 任务 ‘:mergeDebugResources’ ionic 2 执行失败

android - BroadcastReceiver 不会从 ActionBarDrawerToggle 触发

java - 带路径解析器 : Points are too far apart Navigation Drawer

android - 扩展 AppCompatActivity 时 fragment 返回堆栈不起作用

android - AppCompat 问题

Gingerbread 上带有 appcompat 的 Android Up 按钮,标题不可点击

java - OpenGL ES、onDrawFrame 性能

android - Jetty 9 无法在 Android 上运行

Android DrawerLayout - 没有发现重力的抽屉 View