reduce left margin of navigation icon of toolbar in android
12,195
Solution 1
add these line into your toolbar xml
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
Solution 2
Set the style to toolbar:
<!-- Tool Bar-->
<style name="ToolbarStyle" parent="@style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">0dp</item>
<item name="android:paddingLeft">0dp</item>
</style>
And in on Create method of activity do this,
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Author by
Ajay Mistry
I am Computer Engineer Professionally I am Android Developer. Passionate about all Technical, Medical and Pharmaceutical issues.
Updated on June 18, 2022Comments
-
Ajay Mistry almost 2 years
as i'm new to android i set back button in my toolbar, i want to reduce its padding/margin from left how can i do that?? thanks in adwance.
this is my design 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:popupTheme="@style/AppTheme.PopupOverlay"> <TextView android:id="@+id/tripidtoolbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:text="name" android:textColor="#ffffff" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/dayNotoolbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:textColor="#ffffff" android:layout_marginRight="10dp" android:text="day" android:textAllCaps="true" android:textSize="18sp" android:textStyle="bold" /> </android.support.v7.widget.Toolbar>
this is how i manually set back button
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vouchers_details); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setNavigationIcon(R.drawable.arrowbackwhite); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); setSupportActionBar(toolbar);
this is my screen(back button havin left margin)
-
Ajay Mistry about 8 yearsi already create back button i wand to reduce that space coming by default on left side of button.
-
Ajay Mistry almost 8 years..Thanks for Replying....it looks work in Xml Editor .but when i run app in real device there is no change in it. it looks as it is.. do you know why it happans??
-
Calin almost 6 yearsFor this to actually work you also have to set ` <item name="toolbarStyle">@style/ToolbarStyle</item>` in your theme