chanti February 2016

Toolbar and tablaout and frgment to share same background image

i am very new to android i am trying to display one background image to all my tool and tabs and fragment ,i got this background image to my toolbar and tab but how to show same background image to my fragment please any one help me how to do this my Xml code

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:id="@+id/mainActivityBar"
android:layout_alignParentTop="true"
android:background="@drawable/actionbar"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
app:contentInsetRight="0dp"

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="President"
        android:id="@+id/appname_1"
        android:background="@android:color/transparent"
        android:textColor="#ffffff"
        android:layout_marginLeft="20dp" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        style="@style/myCustomTabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:layout_below="@+id/appname_1"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="false"
        android:layout_alignParentLeft="false"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="false"
        android:layout_alignLeft="@+id/appname_1"
        app:tabGravity="fill"
        app:tabMode="scrollable"/>
</RelativeLayout>

I want like below image please any one help me how to get like below image

Answers


Desdroid February 2016

Try to do the following:

Set the background of your TabLayout and Toolbar to transparent. you can do that by this attribute: android:background="@android:color/transparent"

Then set the desired background image to your root view. (In your case its most probably a CoordinatorLayout - you didn't post the full layout).

If you need a code example let me know, but it should be pretty straightforward.

EDIT:

As you requested a code example. It's just as I described above. Instead of CoordinatorLayout as the root layout you can use of course any other layout you need.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/background">

  <android.support.design.widget.AppBarLayout
      android:id="@+id/app_bar_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@android:color/transparent"
      android:theme="@style/AppTheme.AppBarOverlay">

      <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/transparent"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
      <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"/>

  </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

Post Status

Asked in February 2016
Viewed 3,349 times
Voted 11
Answered 1 times

Search




Leave an answer