Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

space between toolbar icon and toolbar title

Tags:

android

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>
like image 741
bipin Avatar asked Mar 10 '16 13:03

bipin


People also ask

What is Toolbar Android?

In Android applications, Toolbar is a kind of ViewGroup that can be placed in the XML layouts of an activity. It was introduced by the Google Android team during the release of Android Lollipop(API 21). The Toolbar is basically the advanced successor of the ActionBar.


2 Answers

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" />
like image 118
splhead Avatar answered Nov 05 '22 12:11

splhead


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"

like image 39
KuTear Avatar answered Nov 05 '22 12:11

KuTear