Kaushik S Kaushik S - 2 months ago 8
Android Question

Can't eliminate margins on all side of a toolbar in android

I'm trying to include a toolbar widget into an activity, but, the toolbar has extra spacing on all sides.

toolbar.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:minHeight="?android:attr/actionBarSize"
android:background="?attr/colorPrimary"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_alignParentTop="true"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
local:contentInsetEnd="0dp"
local:contentInsetStart="0dp"
local:contentInsetLeft="0dp"
local:contentInsetRight="0dp"
/>


Preview of toolbar.xml:

enter image description here

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_gravity="center"
android:orientation="vertical"
tools:context="com.infotoall.newsapp.FacebookLoginActivity">

<include
layout="@layout/toolbar"
android:id="@+id/toolbar"
/>
</LinearLayout>


Preview of layout:

enter image description here

Answer

Remove Padding from your Linear Layout. Remove these lines

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"