1

How can I remove this extra space between the icon in action bar?

See the picture please.enter image description here

Tried everything, nothing seems to work:

    <style name="Widget.Toolbar" parent="@style/Widget.AppCompat.Toolbar">
    <item name="android:paddingRight">0dip</item>
    <item name="android:paddingLeft">0dip</item>
    <item name="android:background">@color/actionBarBackgroundColor</item> <!-- v11 -->
    <item name="background">@color/actionBarBackgroundColor</item>
    <item name="android:width">48dip</item>
</style>
Francisco Souza
  • 806
  • 15
  • 38

3 Answers3

2

You can achieve this through style , Try this

    <style name="AppTheme" parent="android:Theme.Light">
      <item name="android:actionButtonStyle">@style/ActionButtonStyle</item>   
    </style>


    <style name="ActionButtonStyle" parent="@android:style/Widget.Holo.ActionButton">
      <item name="android:minWidth">0dip</item>
      <item name="android:paddingLeft">0dip</item>
      <item name="android:paddingRight">0dip</item>                  
    </style>

Update your manifest as

android:theme="@style/AppTheme" >
Heshan Sandeepa
  • 3,388
  • 2
  • 35
  • 45
0

You can do this my updating actionbar theme like I did, i was using appcomp theme. You need to play with Widget.Toolbar style, like I added padding on both side of actionbar.

<style name="AppTheme" parent="AppTheme.Base">
        <item name="toolbarStyle">@style/Widget.Toolbar</item>
</style>

<style name="Widget.Toolbar" parent="@style/Widget.AppCompat.Toolbar">
        <!-- 16dp padding on both sides of actionbar -->
        <item name="android:paddingRight">16dp</item>
        <item name="android:paddingLeft">16dp</item>
</style>

Update:

The padding on left will not work because Android set size for icon (if i am not wrong) to ~56dp, and actual image is scaled to fit centerInside, which leaves padding within image. So try reducing icon size (width) in style

  • I tried, but didn't work ` ` – Francisco Souza Apr 22 '15 at 13:56
  • try padding 100dp for testing, and see what happen –  Apr 22 '15 at 14:00
  • If I pad 100dp it works, but if I pad 0dp still keep the same left distance, I even tried with -10dp, no success as well – Francisco Souza Apr 22 '15 at 15:24
  • I saw you comment, I just don't find out how to reduce that icon size in width (yet) – Francisco Souza Apr 22 '15 at 20:16
0

This is how I solved using Toolbar from appcompat:

Style:

<style name="Theme.ProTaxi.Passageiro" parent="Theme.AppCompat.Light.NoActionBar"></style>

On the activity:

Toolbar actionBar = (Toolbar) findViewById(R.id.actionBar);
actionBar.setTitle("Title");
actionBar.setSubtitle("Subtitle");
actionBar.setTitleTextColor(Color.parseColor("#846A1A"));

Create a xml file in /layout folder with toolbar and included in each of activity xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:id="@+id/toolbarLayout"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/actionBar"
        android:layout_width="fill_parent"
        android:background="@color/actionBarBackgroundColor"
        android:layout_height="?attr/actionBarSize"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="0dp" >
    </android.support.v7.widget.Toolbar>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#A0A09F" />

</LinearLayout>

Including toolbar.xml in activity layout xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_telas" >

    <LinearLayout
        android:id="@+id/layoutTopToolbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <include layout="@layout/toolbar" />

    </LinearLayout>

    <ListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/listaTaxisLivres"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/layoutTopToolbar"
        android:fastScrollEnabled="true" >
    </ListView>

</RelativeLayout>
Francisco Souza
  • 806
  • 15
  • 38