2016-07-14 76 views
19

這裏的菜單圖標後,大填充縫隙圖片: enter image description here刪除Android工具欄中的漢堡(菜單)圖標後的大填充?

這發生在我的項目不工作了一個月(暑期班)之後。我剛回到它並注意到更新Android Studio後,工具欄上的空白比正常情況下大。我無法在SO上找到任何有關此問題的解決方案。如果任何人都可以幫助,將非常感激。

我做這個加載漢堡包圖標(每行正確放置在應用程序,無論是在類聲明的onCreate(),等我把它像這樣簡單。):

ActionBarDrawerToggle mDrawerToggle; 
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), dl, toolbar, R.string.nav_open, R.string.nav_closed) 
mDrawerToggle.syncState(); 

這裏是我的工具欄的XML代碼:

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:minHeight="?attr/actionBarSize" 
    app:layout_scrollFlags="scroll|enterAlways" 
    app:title="Test Title"> 

</android.support.v7.widget.Toolbar> 

我想插科打諢的各種contentInset XML屬性,但沒有影響的菜單圖標後的間距。

編輯:這link顯示我曾經有(在頁面中間找到)。如果您注意到標題和漢堡包圖標之間的間距,則間距不像此處所示的圖片那麼寬。就好像間距變成了兩倍或者什麼。

+0

的[填充之間,爲其他動作 - 家庭 - 圖標可能重複 - 和標題](http://stackoverflow.com/questions/9737101/padding-between-actionbars-home-icon-and-title) –

+0

對以下兩個答案的補充說明:正如他們所說,應該把它在工具欄中佈局。我試着把它放在主題中,但它並沒有設置爲工具欄佈局的主題。 – vida

回答

43

我想通了!我必須設置

app:contentInsetStartWithNavigation="0dp"

在我Toolbar佈局。

enter image description here

+3

此新填充隨支持庫24.0.0+推出,具體如下:https://code.google.com/p/android/issues/detail?id=213826 – kefs

+0

@kefs有趣。不知道爲什麼,看起來太多間距。 –

+3

謝謝!我們也可以通過編程方式來實現'toolbar.setContentInsetStartWithNavigation(0);' – user25

12

這些屬性添加到您的Toolbar

app:contentInsetLeft="0dp" 
app:contentInsetStart="0dp" 
app:contentInsetStartWithNavigation="0dp" 

這將禁用插圖開始填充Toolbar的標題

+0

https://stackoverflow.com/questions/47207491/remove-padding-between-hamburger-icon-and-toolbar @blueware –