很早就遇到一個(gè)問題,如下圖:
標(biāo)題和左側(cè)的返回鍵間距過大韭赘,之前在做CloudReader的時(shí)候就遇到了,一直沒有解決势就,由于自身強(qiáng)迫癥辞居,心里始終和這個(gè)過不去,就研究了很久終于解決了蛋勺。
之前在網(wǎng)上找了各種解決方法瓦灶,比如給ToolBar設(shè)置
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
不直接給ToolBar設(shè)置字體,在ToolBar里面包裹TextView抱完,還是不行贼陶。
等等...
最后:
將mTitleToolBar.setNavigationIcon(R.drawable.icon_back);
去掉后,發(fā)現(xiàn)標(biāo)題頂格了,于是懷疑是NavigationIcon的問題碉怔。
將app:navigationIcon="@drawable/icon_back"
設(shè)置在ToolBar屬性上后可以直接看到效果烘贴,開始考慮是不是有一個(gè)屬性是設(shè)置NavigationIcon
與title
之間的間距,果然發(fā)現(xiàn)了:
app:contentInsetStartWithNavigation="0dp"
附上完整代碼:
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/title_tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorTheme"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:layout_scrollFlags="enterAlways|scroll"
app:navigationIcon="@drawable/icon_back"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ToolbarStyle"
app:title="標(biāo)題"
app:titleTextColor="@color/colorWhite">
后來直接搜了這個(gè)屬性查了一下撮胧,發(fā)現(xiàn)之前還是有很多人遇到過桨踪,只不過我沒檢索出來,推薦一個(gè)分析的很好的:
- 關(guān)于Toolbar中navigationIcon和title之間距離及展開
-
app:contentInsetStartWithNavigation=“0dp” isn't working in ToolBar - 在外面包裹
AppBarLayout
應(yīng)該也能達(dá)到效果