簡體   English   中英

使用Appcompat v7不顯示導航抽屜圖標

[英]Navigation drawer icon not showing using appcompat v7

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

在此處輸入圖片說明

您可以在上圖中看到,在黑色圓圈中,我想顯示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.support.v4.app.ActionBarDrawerToggle; 導入android.support.v7.app.ActionBarDrawerToggle;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM