U
U
Unkow2014-06-22 18:56:44
Java
Unkow, 2014-06-22 18:56:44

How to set padding or border for icon in ActionBar in Android?

Hello, there is such a problem - too much indentation to the left of the icon. I don’t know why it happened, it’s clearly not the icon itself, I made various icons, through services too.
This is what it looks like:
6c60336bdcf24a34be5aaca50199853f.jpg
My MainActivity:

setContentView(R.layout.activity_main);
    	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        final ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        mSectionsPagerAdapter = new TabPagerAdapter(getSupportFragmentManager());
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setOffscreenPageLimit(mSectionsPagerAdapter.getCount());
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });
        for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
            actionBar.addTab(
                    actionBar.newTab()
                            .setText(mSectionsPagerAdapter.getPageTitle(i))
                            .setTabListener(this));
        }

Well, maybe someone needs a style file:
<resources xmlns:android="http://schemas.android.com/apk/res/android">


    <style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light">
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_Myapp</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Myapp</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Myapp</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Myapp</item>
        <item name="android:actionBarTabTextStyle">@style/tabtextcolor</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Myapp</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Myapp</item>
        <item name="android:actionModeBackground">@drawable/actionmode_style</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_Myapp</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Myapp</item>
        <item name="android:homeAsUpIndicator">@drawable/ic_action_previous_item</item>
        <item name="android:actionOverflowButtonStyle">@style/OverFlow</item>
    </style>
    
    <style name="ActionBar.Solid.Myapp" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
        <item name="android:background">@drawable/ab_solid_Myapp</item>
        <item name="android:backgroundStacked">@drawable/ab_stacked_solid_Myapp</item>
        <item name="android:backgroundSplit">@drawable/ab_bottom_solid_Myapp</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Myapp</item>
    </style>

    <style name="ActionBar.Transparent.Myapp" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:background">@drawable/ab_transparent_Myapp</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Myapp</item>
    </style>

    <style name="PopupMenu.Myapp" parent="@android:style/Widget.Holo.Light.ListPopupWindow">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_Myapp</item>	
    </style>

    <style name="DropDownListView.Myapp" parent="@android:style/Widget.Holo.Light.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_Myapp</item>
    </style>

    <style name="ActionBarTabStyle.Myapp" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
        <item name="android:background">@drawable/tab_indicator_ab_Myapp</item>
    </style>
    
    <style name="tabtextcolor" parent="@android:style/Widget.ActionBar.TabText">
        <item name="android:textColor">@drawable/tab_text_color</item>
        <item name="android:textSize">@dimen/tab_text_size</item>
    </style>

    <style name="DropDownNav.Myapp" parent="@android:style/Widget.Holo.Light.Spinner">
        <item name="android:background">@drawable/spinner_background_ab_Myapp</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_Myapp</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_Myapp</item>
    </style>
    
    <style name="ProgressBar.Myapp" parent="@android:style/Widget.Holo.Light.ProgressBar.Horizontal">
        <item name="android:progressDrawable">@drawable/progress_horizontal_Myapp</item>
    </style>
    
    <style name="ActionButton.CloseMode.Myapp" parent="@android:style/Widget.Holo.Light.ActionButton.CloseMode">
        <item name="android:background">@drawable/btn_cab_done_Myapp</item>
    </style>

    <!-- this style is only referenced in a Light.DarkActionBar based theme -->
    <style name="Theme.Myapp.Widget" parent="@android:style/Theme.Holo">
        <item name="android:popupMenuStyle">@style/PopupMenu.Myapp</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Myapp</item>
    </style>
    
    <style name="login_background">
        <item name="android:background">@drawable/enter_login_style</item>
    </style>
    
    <style name="OverFlow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_action_overflow</item>
    </style>

</resources>

Actually a subject how to correct it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marat S, 2014-06-22
@aratj

An extreme case is to make your own layout for the action bar.
getActionBar().setCustomView(R.id.my_custom_view);
getActionBar().setDisplayShowCustomEnabled(true);
And the standard one, you can see from the source code of the android. what to give id to elements.
it's just that, as far as I remember, there is a "reserved" place for the home button

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question