1

I am trying to get a view (LinearLayout) to feel like an extension of the ActionBar. I am using AppCompat objects btw.

This is my xml:

<android.support.design.widget.CoordinatorLayoutt xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".RegisterActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay.Colored">

        <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" />

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

    <include layout="@layout/content_register" />

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

And now the content_register layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:elevation="4dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:text="text1"
            android:textColor="@color/white" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:text="text2"
            android:textColor="@color/white" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#40FFFFFF" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:text="text3"
            android:textColor="@color/white" />

    </LinearLayout>


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="8dp"
        android:text="insert awesome stuff here" />

</LinearLayout>

What am I trying to do with represented in the following image: Pretended results

And this is what I am getting. Results so far

Any ideas on how I can fix this layout? Am I using the wrong components?

Also, should I be using a CardView for the layout with text1 2 3?

hpinhal
  • 512
  • 6
  • 22

2 Answers2

1

Add this in the styles (for pre-Lolipop devices)

<item name="android:windowContentOverlay">@null</item>

Add this line in your AppBarLayout

app:elevation="0dp"
hpinhal
  • 512
  • 6
  • 22
Sanjay Kakadiya
  • 1,596
  • 1
  • 15
  • 32
  • In which version are you tested ? – Sanjay Kakadiya Apr 29 '16 at 11:29
  • I had to place that in the AppBarLayout. It worked there. – hpinhal Apr 29 '16 at 11:32
  • Android 6. But it shows a really tiny 10% white line between the toolbar and the other view. Any idea on how to fix that? I see apps doing it perfectly, like in this article: http://www.talkandroid.com/253296-todoist-for-android-update-brings-material-design-to-the-forefront/ – hpinhal Apr 29 '16 at 11:33
  • Removing the elevation and adding that, makes it go back to the image I posted in the question. Using both options still shows the line. – hpinhal Apr 29 '16 at 11:47
  • I thing you tried both way please check this may be its help you. http://stackoverflow.com/questions/12246388/remove-shadow-below-actionbar – Sanjay Kakadiya Apr 29 '16 at 11:56
  • Your answer is correct. For pre-Lolipop devices, you need the `android:windowContentOverlay="@null"` in the AppBarLayout theme and for the rest you must specify `app:elevation="0dp"`. I was getting that line because i switched to that CardView and somehow it produces that white line. – hpinhal Apr 29 '16 at 12:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/110694/discussion-between-sanjay-kakadiya-and-heldermpinhal). – Sanjay Kakadiya Apr 30 '16 at 04:02
0

Add to appbar layout and to included layout app:elevation="4dp" this way they will be on same depth level and you will see just elevation of included layout

Tadas
  • 7
  • 6