19

I want to put spaces between toolbar icon and toolbar title and also I want to change the color of statusbar in my app as same as the color of toolbar can anyone help currently it looks like this:

enter image description here

here is my code:

public class AbstractActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_abstract);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.drawable.ic_astrological_sun);
  }
}

<?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="#0F6177"
    app:popupTheme="@style/AppTheme.PopupOverlay" >
    </android.support.v7.widget.Toolbar>
  </LinearLayout>
Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
bipin
  • 1,091
  • 4
  • 12
  • 30

4 Answers4

29

Here adding app:titleMarginStart="32dp" solve.

pay attention on app prefix

in context:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_main"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:layout_scrollFlags="scroll|enterAlways"
    app:logo="@drawable/ic_launcher"
    app:title="@string/app_name"
    app:titleMarginStart="32dp" />
Mohammad
  • 21,175
  • 15
  • 55
  • 84
splhead
  • 390
  • 3
  • 6
15

Use Toolbar default title margin left 16dp And we can change it with app:contentInsetStart="100dp"

Or if you had a navigation icon,the title marigin left 56+16=72dp defalt, So you can change it with app:contentInsetStartWithNavigation="56dp"

KuTear
  • 216
  • 3
  • 8
2

add app:titleMarginStart="12dp" and it works like charm

 <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"
                app:logo="@drawable/ic_arrow_back_white_24dp"
                app:title="@string/app_name"
                app:titleMarginStart="12dp" />
Rahul
  • 3,293
  • 2
  • 31
  • 43
-1

Option 1: Don't recommend:

Set title with space before your text. For example " Your title"

Option 2: Add your custom TextView under your Toolbar and you can custom this TextView in your xml layout or your activity class

For example:

<android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize" 
        android:background="#0F6177" 
        app:popupTheme="@style/AppTheme.PopupOverlay" > 
            <TextView
                android:id="@+id/text_toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:layout_marginLeft="5dp"
                android:text="@string/app_name"
                android:textColor="@android:color/white"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textStyle="bold" />

</android.support.v7.widget.Toolbar> 
thuongle
  • 537
  • 6
  • 10