2016-07-24 96 views
12

我的工具欄如何從工具欄中的標題中刪除填充?

My toolbar

谷歌工具欄播放

GooglePlay toolbar

如何刪除不必要的填充?

我的工具欄片段 我的代碼片段裏面:

public void setUpToolbar(Toolbar toolbar, String title, @DrawableRes int resId) { 
    toolbar.setTitle(title); 
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); 
    ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar(); 
    ab.setHomeAsUpIndicator(resId); 
    ab.setDisplayHomeAsUpEnabled(true); 
} 

我的XML工具欄:

<android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 
+0

http://stackoverflow.com/a/38302389/1462770 – Amir

+4

app:contentInsetStartWithNavigation =「0dp」 – Amir

回答

2

在你的代碼試試這個:

ActionBar actionBar = getSupportActionBar(); 
actionBar.setDisplayShowHomeEnabled(false); 
actionBar.setDisplayShowCustomEnabled(true); 
actionBar.setDisplayShowTitleEnabled(false); 
View customView = getLayoutInflater().inflate(R.layout.main_action_bar, null); 
actionBar.setCustomView(customView); 
Toolbar parent =(Toolbar) customView.getParent(); 
parent.setContentInsetsAbsolute(0,0); 
+0

不,它沒有幫助 – gape

+0

@gape現在嘗試它,讓我知道 –

7

只需添加在您的工具欄中

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

它應該工作

1

嘗試添加應用程序:contentInsetLeft:

<android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:contentInsetLeft="0dp" 
      app:contentInsetStart="0dp" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 
9

使用該工具欄的XML標籤內

app:contentInsetStartWithNavigation="0dp" 
+0

這是爲我工作的那個。謝謝!! –

+0

最受歡迎:) –

相關問題