Padding Between Actionbar's Home Icon and Title

Padding between ActionBar's home icon and title

I adapted Cliffus answer and assigned the logo-drawable in my actionbar style definition, for instance like this in res/style.xml:

<item name="android:actionBarStyle">@style/MyActionBar</item>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#3f51b5</item>
<item name="android:titleTextStyle">@style/ActionBar.TitleText</item>
<item name="android:textColor">#fff</item>
<item name="android:textSize">18sp</item>
<item name="android:logo">@drawable/actionbar_space_between_icon_and_title</item>
</style>

The drawable looks like Cliffus' one (here with the default app launcher icon) in res/drawable/actionbar_space_between_icon_and_title.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ic_launcher"
android:right="20dp"/>
</layer-list>

In the android_manifest.xml you can still set a different app icon (launcher icon on 'desktop'. Any different logo definition here are visible in activities without an action bar.

Spacing between Action bar icon and Title.

I added some spacing like this:

actionBar.setTitle("  " + myTitle);

I don't think it should be done this way but I've searched a lot I couldn't find any solution for this without using custom view which I can't because I'm using AB tabs.

So if anyone else has a better (cleaner) solution, do answer. For others, this works better than anything else I tried.

Cheers!

How to increase padding or margin between menu item icon and title in app toolbar?

I can't believe it took me so long to figure this out!

Eventually it occurred to me to use the Android Device Monitor. I went to Tools > Android > Android Device Monitor. When that started up, I clicked the package name of my app in the "Devices" tab and then I clicked the "Dump View Hierarchy for UI Automator" button (which looks like multiple phones stacked on top of each other) at the top of the "Devices" tab. This showed me the UI of my current screen. Then I could click on the "Refresh" button and discover that it was not two Views next to each other--it was one TextView with a DrawableLeft. I know, I know, that's obvious and should have been the first thing I thought of.

I had already found ActionBarSherlock - How to set the padding of each actionbar's icon? , but that didn't work for me. However, that gave me an example of something I needed--changing the ActionButton style.

Now that I knew it was a TextView with a DrawableLeft, I knew I needed to change DrawablePadding. That's the change I needed to make to styles.

To change the ActionButton theme I needed to add this to my styles.xml:

<style name="ActionButton" parent="@android:style/Widget.ActionButton">
<item name="android:drawablePadding">@dimen/action_button_padding</item>
</style>

dimen.xml:

<dimen name="action_button_padding">4dp</dimen>

Then a tweak to the Theme section of style.xml:

<style name="Theme.MyTheme"
parent="Theme.AppCompat.Light.NoActionBar">
<!-- other styles -->
<item name="android:actionButtonStyle">@style/ActionButton</item>
</style>

And it just works! No need to set a custom ActionProvider, edit the image to add spacing in the image file, or use extra XML files for each button.

Padding / space in Toolbar between icon and title (Android 24)

You can add this attribute in toolbar to avoid this padding.

app:contentInsetStartWithNavigation="0dp"

how to reduce the space between icon and home up key in custom action bar in android

you can use toolbar property for this

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"

like this use in toolbar

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp" />

ActionBar`s title text padding

You problem will not resolve so easy with Styles... The best solution is create a CustomView to you actionBar and use it!
Sometimes styles padding in actionbar(title) doesn't work on some devices.

Example: -> http://javatechig.com/android/actionbar-with-custom-view-example-in-android

Good Luck!

How to reduce the gap between navigation icon and toolbar title?

Add

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"

to the ToolBar.

Complete Code :

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp" />


Related Topics



Leave a reply



Submit