解決Android V7后自定義Toolbar、ActionBar左側(cè)有空白問(wèn)題
如圖所示:

1.查看Wiget.AppCompat.Toolbar的parent主題,如下所示:
<style name="Base.Widget.AppCompat.Toolbar" parent="android:Widget"> <item name="titleTextAppearance">@style/TextAppearance.Widget.AppCompat.Toolbar.Title</item> <item name="subtitleTextAppearance">@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle</item> <item name="android:minHeight">?attr/actionBarSize</item> <item name="titleMargins">4dp</item> <item name="maxButtonHeight">56dp</item> <item name="collapseIcon">?attr/homeAsUpIndicator</item> <item name="collapseContentDescription">@string/abc_toolbar_collapse_description</item> <item name="contentInsetStart">16dp</item> </style>
其中,contentInsetStart這個(gè)屬性就是引起自定義ActionBar不能完全填充的原因。
解決方法:
在styles.xml中定義新的style繼承自Wiget.AppCompat.Toolbar如下:
<style name="ClubToolbar" parent="Widget.AppCompat.Toolbar"> <item name="contentInsetStart">0dp</item><!-- 設(shè)置該屬性解決空白部分--> </style>
然后在你的style.xml中AppTheme里重寫toolbar屬性:
<!-- Base application theme. “NoActionBar”隱藏原有的Actionbar 設(shè)置Toolbar --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> //..... <item name="toolbarStyle">@style/ClubToolbar</item> </style>
2.也有另一個(gè)解決方法:
直接寫到布局里,如下所示:
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorTheme"
app:contentInsetStart="0.0dp"
app:layout_scrollFlags="enterAlways|scroll"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ToolbarStyle" />
app:contentInsetStart=”0.0dp”即可
以上所述是小編給大家介紹的解決Android V7后自定義Toolbar、ActionBar左側(cè)有空白問(wèn)題,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Android動(dòng)態(tài)修改ToolBar的Menu菜單示例
- Android中Toolbar隨著ScrollView滑動(dòng)透明度漸變效果實(shí)現(xiàn)
- Android折疊式Toolbar使用完全解析(CollapsingToolbarLayout)
- Android自定義Toolbar使用方法詳解
- Android ToolBar控件詳解及實(shí)例
- Android自定義ActionProvider ToolBar實(shí)現(xiàn)Menu小紅點(diǎn)
- Android5.0+ CollapsingToolbarLayout使用詳解
- Android ToolBar整合實(shí)例使用方法詳解
- Android中ActionBar和ToolBar添加返回箭頭的實(shí)例代碼
- android ToolBar的簡(jiǎn)單使用
相關(guān)文章
Android從0到完整項(xiàng)目(1)使用Android studio 創(chuàng)建項(xiàng)目詳解
本篇文章主要介紹了Android從0到完整項(xiàng)目(1)使用Android studio 創(chuàng)建項(xiàng)目詳解,具有一定的參考價(jià)值,有興趣的可以了解一下2017-07-07
android studio集成ijkplayer的示例代碼
本篇文章主要介紹了android studio集成ijkplayer的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
flutter自定義InheritedProvider實(shí)現(xiàn)狀態(tài)管理詳解
這篇文章主要為大家介紹了flutter自定義InheritedProvider實(shí)現(xiàn)狀態(tài)管理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
Android 聽筒模式的具體實(shí)現(xiàn)實(shí)例
這篇文章主要介紹了Android 聽筒模式的具體實(shí)現(xiàn)實(shí)例,有需要的朋友可以參考一下2013-12-12
Android 截取手機(jī)屏幕兩種實(shí)現(xiàn)方法
這篇文章主要介紹了Android 截取手機(jī)屏幕兩種實(shí)現(xiàn)方法的相關(guān)資料,需要的朋友可以參考下2017-05-05
android使用webwiew載入頁(yè)面使用示例(Hybrid App開發(fā))
Hybrid App 融合 Web App 的原理就是嵌入一個(gè)WebView組件,可以在這個(gè)組件中載入頁(yè)面,相當(dāng)于內(nèi)嵌的瀏覽器,下面是使用示例2014-03-03
安卓中出現(xiàn)過(guò)的一些容易被忽略的異常整理
今天小編就為大家分享一篇關(guān)于安卓中出現(xiàn)過(guò)的一些容易被忽略的異常整理,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12
Android開發(fā)之利用jsoup解析HTML頁(yè)面的方法
這篇文章主要介紹了Android開發(fā)之利用jsoup解析HTML頁(yè)面的方法,結(jié)合實(shí)例形式分析了Android基于jsoup jar包來(lái)抓取html頁(yè)面的實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-03-03
Android onMeasure與onDraw及自定義屬性使用示例
這篇文章主要介紹了Android onMeasure與onDraw及自定義屬性使用示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-02-02

