Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

My problem is the extra space between the nav-drawer icon and toolbar title. The sample images are below:

spacing between nav-drawer icon and title

spacing between back icon and toolbar

The xml view of the toolbar is

<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" /> 

I have tried to solve this problem by using code below but no change occurred.

@Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_home);     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);     setSupportActionBar(toolbar);      //toolbar.setTitleMarginStart(0);     toolbar.setTitleMarginStart(-8); } 

Is there any way to solve this problem ?

like image 631
Sagar Chapagain Avatar asked Nov 21 '16 10:11

Sagar Chapagain


People also ask

What is the layout for toolbar?

In Android applications, Toolbar is a kind of ViewGroup that can be placed in the XML layouts of an activity.

How do I hide navigation icons?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

What is widget toolbar?

android.widget.Toolbar. A standard toolbar for use within application content. A Toolbar is a generalization of action bars for use within application layouts.


1 Answers

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" /> 
like image 141
Harshad Pansuriya Avatar answered Sep 28 '22 15:09

Harshad Pansuriya