解決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開(kāi)發(fā)實(shí)現(xiàn)的簡(jiǎn)單五子棋游戲示例
這篇文章主要介紹了Android開(kāi)發(fā)實(shí)現(xiàn)的簡(jiǎn)單五子棋游戲,結(jié)合實(shí)例形式分析了Android實(shí)現(xiàn)五子棋游戲功能的布局、游戲功能等具體實(shí)現(xiàn)步驟與相關(guān)算法實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-12-12Flutter 實(shí)現(xiàn)網(wǎng)易云音樂(lè)字幕的代碼
這篇文章主要介紹了Flutter 實(shí)現(xiàn)網(wǎng)易云音樂(lè)字幕的代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04Android實(shí)現(xiàn)recyclerview城市字母索引列表
大家好,本篇文章主要講的是Android實(shí)現(xiàn)recyclerview城市字母索引列表,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下2022-01-01Android仿滴滴出行驗(yàn)證碼輸入框功能實(shí)例代碼
最近項(xiàng)目經(jīng)理交給我們組一個(gè)類似滴滴出行填寫驗(yàn)證碼的彈框功能,拿到這個(gè)項(xiàng)目需求真是把我忙暈了,下面通過(guò)本文給大家分享Android仿滴滴出行驗(yàn)證碼輸入框功能實(shí)例代碼,需要的朋友參考下吧2017-12-12Kotlin自定義實(shí)現(xiàn)支付密碼數(shù)字鍵盤的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Kotlin如何自定義實(shí)現(xiàn)支付密碼數(shù)字鍵盤的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07使用RoundedBitmapDrawable生成圓角圖片的方法
由于RoundedBitmapDrawable類沒(méi)有直接提供生成圓形圖片的方法,所以生成圓形圖片首先需要對(duì)原始圖片進(jìn)行裁剪,將圖片裁剪成正方形,最后再生成圓形圖片,具體實(shí)現(xiàn)方法,可以參考下本文2016-09-09android使用PullToRefresh實(shí)現(xiàn)下拉刷新和上拉加載
本篇文章主要介紹了android使用PullToRefresh實(shí)現(xiàn)下拉刷新和上拉加載,具有一定的參考價(jià)值,有興趣的可以了解一下。2016-12-12Android5.0以上版本錄屏實(shí)現(xiàn)代碼(完整代碼)
這篇文章主要介紹了Android5.0以上版本錄屏實(shí)現(xiàn)代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-01-01Android中使用socket通信實(shí)現(xiàn)消息推送的方法詳解
這篇文章主要介紹了Android中使用socket通信實(shí)現(xiàn)消息推送的方法,文中舉了一個(gè)消息發(fā)送端和一個(gè)消息接收端以及服務(wù)器端的例子來(lái)說(shuō)明原理并且展示了客戶端的實(shí)現(xiàn),需要的朋友可以參考下2016-04-04