簡體   English   中英

沒有應用程序圖標的Android導航抽屜

[英]Android Navigation Drawer Without App Icon

我有一個導航抽屜,在通用的“此按鈕打開幻燈片菜單”按鈕(一個由三條水平線組成的按鈕)旁邊,無論我將應用程序圖標設置在它旁邊。 我不能簡單地將圖像替換為空白圖像,因為當您嘗試打開應用程序時,沒有應用程序圖標。 有沒有辦法在不影響應用程序圖標的情況下將其從導航抽屜中刪除? 我已經在抽屜設置中查看了代碼,對其進行了設置。 我似乎找不到此圖標被添加到標題欄的位置。

這是我創建菜單的代碼:

private void setupDrawer(){
    mTitle = mDrawerTitle = getTitle();
    mForumTitles = getResources().getStringArray(R.array.main_menu_array); 

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


    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this,
            R.layout.drawer_list_item, mForumTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);


    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(
            this,                  /* host Activity */
            mDrawerLayout,         /* DrawerLayout object */
            R.drawable.ic_drawer,  /* nav drawer image to replace 'Up' caret */

            R.string.drawer_open,  /* "open drawer" description for accessibility */
            R.string.drawer_close  /* "close drawer" description for accessibility */
            ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle("Menu");
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            //getActionBar().setTitle(mDrawerTitle);

            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

有任何想法嗎? 我將發布必要的代碼或xml文件的任何其他部分。

您可以在樣式定義中隱藏操作欄中的圖標。 檢查此答案以了解操作方法。

您應該做的是將徽標作為首頁指示器添加,而不是3條:

<item name="displayOptions">showHome|showTitle|homeAsUp</item>      
<item name="homeAsUpIndicator">R.drawable.icon</item>

到您的樣式,其父項必須是Theme.AppCompat

actionBarDrawerToggle.setDrawerIndicatorEnabled(false);

就我而言,導航按鈕是不可見的,但仍然占據了該位置,因此我設法通過上述代碼將其從工具欄中完全刪除了。 以防萬一,對於那些正在自定義其工具欄和DrawerLayout的人。

暫無
暫無

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

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