2

I do have a toolbar right now, but I don't really understand a lot of the things that I needed to add and copypaste from tutorials and other questions to get it to work. Also, my toolbar doesn't display an elevation even though I set android:elevation to 9dp.

Similar to the Google I/O app, I've set up a resource in /layout for my toolbar. I copied the name and named it "toolbar_actionbar_with_headerbar". Please excuse that it doesn't make any sense.

This is the content:

toolbar_actionbar_with_headerbar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="128dp">
    <Toolbar
        android:id="@+id/toolbar"
        android:elevation="9dp"
        android:layout_height="128dp"
        android:layout_width="match_parent"
        android:minHeight="?android:attr/actionBarSize"
        android:background="?android:attr/colorPrimary"
        android:gravity="bottom" />
</LinearLayout>

Now, as it's apparently supposed to be done, I am applying my toolbar to activities by including them in their /layout XML-file. Works fine.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    [...]
    <include layout="@layout/toolbar_actionbar_with_headerbar" />
    [...]
</RelativeLayout>

However, this is my first question. When I did that initially, my toolbar was cut off at the sides like all other content of the activity, according to the margins set at the beginning of the xml. Right now, I simply deleted those, and add margins for every text field and other things on the activity. There probably is a better way?

The second question is: Why doesn't my elevation work? I've even tried setting it through code onCreate, but that doesn't work either. And lastly, what would I have to do to properly support devices pre-Level21?

Thanks a lot.

rnrneverdies
  • 15,243
  • 9
  • 65
  • 95

1 Answers1

0

You should read this post: appcompat-v21

Take care when you copy some code text, there are some ” that are wrong, and you should change to ".

About elevation (you can read it in the post too), it only works with lollipop.

JavierSegoviaCordoba
  • 6,531
  • 9
  • 37
  • 51
  • Thanks, I'll read that! However I do run the app on Lollipop (Nexus 6) and the drop shadow is nowhere to be seen. Also won't show up in the preview. – Jason Efstathiou Jan 28 '15 at 21:11
  • @JasonEfstathiou mmm you set some elevation to your relative layout? If two views has the same elevation, there isn't shadow. Have you try to add the elevation to the linear layout that content the toolbar? – JavierSegoviaCordoba Jan 28 '15 at 21:16