通过样式更改ActionBar内容填充

时间:2017-04-12 17:13:22

标签: android android-actionbar material-design android-styles

我一直在阅读这篇文章并发现它附带了SDK 24并且已经找到了工具栏额外边距/填充的解决方案,只需设置:app:contentInsetStartWithNavigation="0dp"

问题是,我的大多数活动布局都没有主题"没有操作栏",例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="package">
        <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listViewContato" />
</LinearLayout>

所以在这种情况下,我怎么能删除多余的边距/填充?因为添加工具栏会改变所有活动会很烦人...

1 个答案:

答案 0 :(得分:0)

您可以为活动定义自定义样式:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>

<style name="MyActionBarStyle" parent="Widget.AppCompat.Light.ActionBar.Solid">
    <item name="contentInsetStart">0dp</item>
    <item name="contentInsetEnd">0dp</item>
    <item name="contentInsetStartWithNavigation">0dp</item>
</style>