6

如何使用 XML 主题更改操作栏图标或徽标空间的顶部和底部填充或边距?

<style name="Theme.Whycheck" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarItemBackground">@drawable/selectable_background_whycheck</item>
    <item name="actionBarStyle">@style/ActionBar.Solid.Whycheck</item>
    <item name="actionModeBackground">@drawable/cab_background_top_whycheck</item>
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_whycheck</item>

            <!-- Light.DarkActionBar specific -->
    <item name="actionBarWidgetTheme">@style/Theme.Whycheck.Widget</item>

</style>

<style name="ActionBar.Solid.Whycheck" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="background">@drawable/ab_solid_whycheck</item>
    <item name="backgroundStacked">@drawable/ab_stacked_solid_whycheck</item>
    <item name="backgroundSplit">@drawable/ab_bottom_solid_whycheck</item>
</style>

<style name="ActionBar.Transparent.Whycheck" parent="@style/Widget.AppCompat.ActionBar">
    <item name="background">@drawable/ab_transparent_whycheck</item>
</style>

<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Whycheck.Widget" parent="@style/Theme.AppCompat">
</style>

提供了我的风格。

4

5 回答 5

2

您可以尝试在操作栏中为您的图标创建一个新样式,如下所示: *将此代码添加到您的 styles.xml

    <!-- style for Action Bar -->
<style name="MyActionBarTabStyle" parent="android:style/Widget.Holo.Light.ActionBarView">
    <item name="android:background">@drawable/actionbar_tab_bg</item>
    <item name="android:paddingLeft">32dp</item>
    <item name="android:paddingRight">32dp</item>
</style>

*将您的样式添加到 UI 操作栏。

您还可以看到这个示例 自定义操作栏

于 2013-09-11T07:43:17.983 回答
0

将您的自定义视图用于操作栏并使用 actionBar.setCustomView(View) 设置视图并设置 actionBar.setDisplayShowCustomEnabled(true) 。请参阅链接ActionBar - 具有居中 ImageView、两侧的操作项的自定义视图

于 2013-09-10T15:13:40.833 回答
0

您可以尝试制作自定义视图,并根据需要在其中指定图标边距: getActionBar().setCustomView(R.id.your_custom_view);

于 2013-09-10T15:17:01.643 回答
0

将此行添加到清单中标记android:theme="@style/MyTheme"下应用的主题中application

<item name="android:actionButtonStyle">@style/ActionButtonStyle</item>

<style name="ActionButtonStyle" parent="@android:style/Widget.Holo.Light.ActionButton">
        <item name="android:minWidth">80dip</item>
        <item name="android:paddingLeft">10dip</item>
        <item name="android:paddingRight">10dip</item>
        <item name="colorPrimaryDark">@color/jd_white</item>
    </style> 

在您相同的 style.xml 中

于 2015-12-22T13:41:51.687 回答
-6

<style name="Theme.Whycheck" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarItemBackground">@drawable/selectable_background_whycheck</item>
    <item name="actionBarItemBackground">@drawable/selectable_background_whycheck</item>

    <item name="android:popupMenuStyle">@style/PopupMenu.Whycheck</item>
    <item name="popupMenuStyle">@style/PopupMenu.Whycheck</item>

    <item name="android:dropDownListViewStyle">@style/DropDownListView.Whycheck</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.Whycheck</item>

    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Whycheck</item>
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.Whycheck</item>

    <item name="android:actionDropDownStyle">@style/DropDownNav.Whycheck</item>
    <item name="actionDropDownStyle">@style/DropDownNav.Whycheck</item>

    <item name="android:actionBarStyle">@style/ActionBar.Solid.Whycheck</item>
    <item name="actionBarStyle">@style/ActionBar.Solid.Whycheck</item>

    <item name="android:actionModeBackground">@drawable/cab_background_top_whycheck</item>
    <item name="actionModeBackground">@drawable/cab_background_top_whycheck</item>

    <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_whycheck</item>
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_whycheck</item>

    <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Whycheck</item>
    <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Whycheck</item>

            <!-- Light.DarkActionBar specific -->
    <item name="android:actionBarWidgetTheme">@style/Theme.Whycheck.Widget</item>
    <item name="actionBarWidgetTheme">@style/Theme.Whycheck.Widget</item>
</style>

<style name="ActionBar.Solid.Whycheck" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/ab_solid_whycheck</item>
    <item name="background">@drawable/ab_solid_whycheck</item>

    <item name="android:backgroundStacked">@drawable/ab_stacked_solid_whycheck</item>
    <item name="backgroundStacked">@drawable/ab_stacked_solid_whycheck</item>

    <item name="android:backgroundSplit">@drawable/ab_bottom_solid_whycheck</item>
    <item name="backgroundSplit">@drawable/ab_bottom_solid_whycheck</item>

    <item name="android:progressBarStyle">@style/ProgressBar.Whycheck</item>
    <item name="progressBarStyle">@style/ProgressBar.Whycheck</item>
</style>

<style name="ActionBar.Transparent.Whycheck" parent="@style/Widget.AppCompat.ActionBar">
    <item name="background">@drawable/ab_transparent_whycheck</item>
    <item name="android:background">@drawable/ab_transparent_whycheck</item>

    <item name="progressBarStyle">@style/ProgressBar.Whycheck</item>
    <item name="android:progressBarStyle">@style/ProgressBar.Whycheck</item>
</style>

<style name="PopupMenu.Whycheck" parent="@style/Widget.AppCompat.PopupMenu">    
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_whycheck</item>  
</style>

<style name="DropDownListView.Whycheck" parent="@style/Widget.AppCompat.ListView.DropDown">
    <item name="android:listSelector">@drawable/selectable_background_whycheck</item>
</style>

<style name="ActionBarTabStyle.Whycheck" parent="@style/Widget.AppCompat.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator_ab_whycheck</item>
</style>

<style name="DropDownNav.Whycheck" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
    <item name="android:background">@drawable/spinner_background_ab_whycheck</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_whycheck</item>
    <item name="android:dropDownSelector">@drawable/selectable_background_whycheck</item>
</style>

<style name="ProgressBar.Whycheck" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
    <item name="android:progressDrawable">@drawable/progress_horizontal_whycheck</item>
</style>

<style name="ActionButton.CloseMode.Whycheck" parent="@style/Widget.AppCompat.ActionButton.CloseMode">
    <item name="android:background">@drawable/btn_cab_done_whycheck</item>
</style>

<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Whycheck.Widget" parent="@style/Theme.AppCompat">
    <item name="popupMenuStyle">@style/PopupMenu.Whycheck</item>
    <item name="android:popupMenuStyle">@style/PopupMenu.Whycheck</item>

    <item name="dropDownListViewStyle">@style/DropDownListView.Whycheck</item>
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Whycheck</item>
</style>

于 2013-09-11T18:57:58.343 回答