2

我正在通过对我的活动使用以下样式来使用叠加操作栏

样式.xml

    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat" >
    <item name="windowActionBarOverlay">true</item>
    <item name="android:background">#00f3ead8</item>
    <item name="android:windowBackground">@drawable/logo1024</item>
</style>

我只有一个要始终显示的菜单项

菜单.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<item
    android:id="@+id/menusettings"
    android:orderInCategory="100"
    android:icon="@drawable/settings"
    android:title="Menu"
    yourapp:showAsAction="always"
    />
  <menu>

图标,即 settings.png 被 8dp 填充但我希望顶部和底部的填充为 0,以便它覆盖整个操作栏

请在项目截止日期前帮助我解决深陷困境提前致谢

4

2 回答 2

3

一年后...删除 v7.Toolbar 的操作按钮上的填充仍然具有挑战性。经过大量实验,这里是一个可行的解决方案,在 API 15 及更高版本上进行了测试(理论上应该可以工作 > API 7)。首先,工具栏样式(主题)应该像这样应用

<android.support.v7.widget.Toolbar
     app:theme="@style/AppTheme.Toolbar"
     android:layout_width="match_parent"
     android:layout_height="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>

下一个,values/styles.xml

<style name="AppTheme.Toolbar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="actionButtonStyle">@style/AppTheme.Toolbar.ActionButton</item>
</style>
<!-- this will be applied regardless api version -->
<style name="Base.AppTheme.Toolbar.ActionButton" parent="@style/Widget.AppCompat.ActionButton">
    <item name="android:minWidth">0dp</item>
    <item name="android:minHeight">0dp</item>
</style>

<!-- this will be applied on < API 17 -->
<style name="AppTheme.Toolbar.ActionButton" parent="@style/Base.AppTheme.Toolbar.ActionButton">
    <item name="android:padding">0dp</item>
</style>

最后一步,values-v17/styles.xml

<!-- this will be applied on >= API 17 -->
<style name="AppTheme.Toolbar.ActionButton" parent="@style/Base.AppTheme.Toolbar.ActionButton">
    <item name="android:paddingStart">0dp</item>
    <item name="android:paddingEnd">0dp</item>
</style>
于 2016-06-02T09:31:25.550 回答
0

那么你的问题是大约一年前的,但它可能对其他人有所帮助。

在此处查看解决方案: 如何在 android 的菜单项之间添加填充?

单独设置填充可能无济于事。您也必须使用 minWidth 属性。我也在使用 AppCompat,绝对有效。

<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionButtonStyle">@style/Widget.Styled.Base.ActionButton</item>
</style>

<style name="Widget.Styled.Base.ActionButton" parent="@style/Widget.AppCompat.Base.ActionButton">
    <item name="android:minWidth">20dp</item>
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">15dp</item>
</style>
于 2014-10-02T13:55:02.510 回答