how to change the padding or margin of the action

2019-03-29 20:02发布

how to change the top and bottom padding or margin of the action bar icon or logo space by using XML theme?

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

Provided my styles.

5条回答
神经病院院长
2楼-- · 2019-03-29 20:13

you can try to make a custom view, and specifi the icon margin in it as you want: getActionBar().setCustomView(R.id.your_custom_view);

查看更多
走好不送
3楼-- · 2019-03-29 20:18

You can try to create a new style for your icon in action bar like this : *Add this code in your 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>

*add your style to the UI action bar .

Also you can see this exemple customizing-action-bar

查看更多
beautiful°
4楼-- · 2019-03-29 20:29

add this line to your theme android:theme="@style/MyTheme"applied under application tag in manifest

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

And

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

in your same style.xml

查看更多
The star\"
5楼-- · 2019-03-29 20:32

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

查看更多
来,给爷笑一个
6楼-- · 2019-03-29 20:38

use your custom view for action bar and set the view using actionBar.setCustomView(View) & also set actionBar.setDisplayShowCustomEnabled(true) . Refer to the link ActionBar - custom view with centered ImageView, Action Items on sides

查看更多
登录 后发表回答