Android Snackbar does not take full width when trying to inflate custom layout
<p>I am trying to change the snackbar with my custom layout but custom layout does not take full width of snackbar.Why?</p>

<p>Here is my code:-</p>

<pre><code>        CoordinatorLayout snackbarCoordinatorLayout;

        snackbarCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.snackbarCoordinatorLayout);
        RelativeLayout objRelativeLayout = new RelativeLayout(mContext);
        RelativeLayout.LayoutParams objLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        // Create the Snackbar
        final Snackbar snackbar = Snackbar.make(snackbarCoordinatorLayout, "", Snackbar.LENGTH_INDEFINITE);
        // Get the Snackbar's layout view
        Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();

        TextView textView = (TextView) layout.findViewById(android.support.design.R.id.snackbar_text);
        textView.setVisibility(View.INVISIBLE);

        LayoutInflater objLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View snackView = objLayoutInflater.inflate(R.layout.snackbar_layout, null);// use the parent ViewGroup instead of null        // Configure the view

        Button btnInvite = (Button) snackView.findViewById(R.id.btn_invite_snackbar);
        Button btnCancel = (Button) snackView.findViewById(R.id.btn_close_snackbar);

        btnInvite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
                launchShareActivity();
            }
        });

        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackView.setLayoutParams(objLayoutParams);
        layout.addView(snackView, 0);
        snackbar.show();
</code></pre>

<p>Here is snackbar_layout.xml and cordinator layout file content:-</p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:background="#000"&gt;

        &lt;Button
            android:id="@+id/btn_invite_snackbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/rounded_bg"
            android:includeFontPadding="false"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:text="@string/invite_your_friends_to_studyboard"
            android:textAllCaps="false"
            android:textColor="@color/white" /&gt;

        &lt;Button
            android:id="@+id/btn_close_snackbar"
            android:layout_width="45dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:background="@android:color/transparent"
            android:gravity="center_horizontal|center_vertical"
            android:text="X"
            android:textColor="@color/white"
            android:textSize="22sp" /&gt;
    &lt;/RelativeLayout&gt;
&lt;!--Cordinator Layout used--&gt;
        &lt;android.support.design.widget.CoordinatorLayout
            android:id="@+id/snackbarCoordinatorLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"&gt;
&lt;android.support.v4.view.ViewPager
                    android:id="@+id/home_view_pager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@null"&gt;

                &lt;/android.support.v4.view.ViewPager&gt;

        &lt;/android.support.design.widget.CoordinatorLayout&gt;
</code></pre>

<p>Here is the output shown in image:-
<a href="https://i.stack.imgur.com/gW3NW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gW3NW.png" alt="You can sees the portion with black background is the actual inflated layout"></a></p>