Dev Sharma
Dev Sharma

Reputation: 674

Remove Left margin from TabLayout

I am using TabLayout inside Toolbar with four tabs. I'm getting left margin for the TabLayout. How can I remove the margin so that the TabLayout fills the Toolbar?

<android.support.v7.widget.Toolbar
    android:id="@+id/tabsToolbar"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_below="@id/custom_toolbar"
    android:background="@color/white">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:tabBackground="@drawable/tab_color_selector"
        app:tabGravity="fill"
        app:tabMode="fixed">

        <android.support.design.widget.TabItem
            android:id="@+id/ti1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tata CLIQ" />

        <android.support.design.widget.TabItem
            android:id="@+id/ti4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Paytm Mall" />
    </android.support.design.widget.TabLayout>
</android.support.v7.widget.Toolbar>

Upvotes: 0

Views: 333

Answers (2)

user4571931
user4571931

Reputation:

Try this code.. only add this below things into toolbar..

  android:contentInsetStart="0dp"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    android:contentInsetRight="0dp"
    android:contentInsetEnd="0dp"
    app:contentInsetRight="0dp"
    app:contentInsetEnd="0dp"





<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
    android:id="@+id/tabsToolbar"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="#fff"
    android:contentInsetStart="0dp"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    android:contentInsetRight="0dp"
    android:contentInsetEnd="0dp"
    app:contentInsetRight="0dp"
    app:contentInsetEnd="0dp"
    >

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:tabGravity="fill">

        <android.support.design.widget.TabItem
            android:id="@+id/ti1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tata CLIQ" />

        <android.support.design.widget.TabItem
            android:id="@+id/ti4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Paytm Mall" />
    </android.support.design.widget.TabLayout>
</android.support.v7.widget.Toolbar>

Upvotes: 2

Harish Jose
Harish Jose

Reputation: 326

Add

app:contentInsetStartWithNavigation="0dp"

in the toolbar tag.

<android.support.v7.widget.Toolbar
    android:id="@+id/tabsToolbar"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_below="@id/custom_toolbar"
    android:background="@color/white"
    app:contentInsetStartWithNavigation="0dp">

Upvotes: 1

Related Questions