如何更改XML主题中操作栏图标或徽标的填充或边距?

时间:2013-09-10 15:04:15

标签: android android-actionbar

如何使用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>

提供我的风格。

5 个答案:

答案 0 :(得分:3)

您可以尝试在操作栏中为您的图标创建一个新样式,如下所示: *在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操作栏。

你也可以看到这个例子 customizing-action-bar

答案 1 :(得分:0)

使用自定义视图操作栏并使用actionBar.setCustomView(View)&amp ;;设置视图。还设置actionBar.setDisplayShowCustomEnabled(true)。请参阅链接ActionBar - custom view with centered ImageView, Action Items on sides

答案 2 :(得分:0)

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

答案 3 :(得分: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中

答案 4 :(得分:-5)

<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>