Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reduce left margin of navigation icon of toolbar in android

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 having left margin)

like image 563
Ajay Mistry Avatar asked Apr 21 '16 10:04

Ajay Mistry


2 Answers

add these line into your toolbar xml

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
like image 75
Abdul Rizwan Avatar answered Oct 20 '22 14:10

Abdul Rizwan


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);
like image 1
Pradeep Gupta Avatar answered Oct 20 '22 13:10

Pradeep Gupta