I have the following Navigation Drawer menu setup:
Main layout activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/colorPrimaryDark"
android:fitsSystemWindows="true"
android:theme="#style/NavigationViewStyle"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" >
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
My menu activity_main_drawer.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/nav_profile"
app:actionLayout="#layout/menu_item"
android:title=""/>
</menu>
Menu item menu_item.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="match_parent">
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:src="#drawable/menu_icon"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu Title"
android:textSize="16sp"
android:textColor="#color/white"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
The result I get is this:
Result i am getting
Instead I want it to be horizontally centered, what did I do wrong here? I have tried many fixes with the custom layout's gravity (menu_item.xml) as well as the items, nothing seems to work.
I don't know if the app:actionLayout in the menu can be centered or not at all, if not please tell me what is the correct way to make an item like that with the alignment I want.
Thanks in advance.
Try this for the
menu_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="#+id/image_view"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_gravity="center|center_horizontal"
android:src="#drawable/menu_icon" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/image_view"
android:layout_gravity="center_horizontal|center"
android:gravity="center"
android:text="Menu Title"
android:textColor="#color/white"
android:textSize="16sp" />
</RelativeLayout>
Hope this helps
Try this, menu_item.xml you can set gravity to center_horizontal.
Related
I currently have a bug in my application. The ListView which is inside a fragment doesn't display all Items. Here's a Screenshot:
Screenshot of the ListView
It should be counting to 50. But it's only counting to 30 (which is cutted of).
Here's my ListView Item Row Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView_listview_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginTop="#dimen/_4sdp"
android:text="TextView"
android:textAlignment="center"
android:textSize="#dimen/_18ssp"
android:gravity="center"
android:layout_gravity="center_vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
</RelativeLayout>
And here is my fragment with the listView:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".GeneralFragment">
<ListView
android:id="#+id/listViewGeneral"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
Thank you :)
Firstly, your fragment layout should be like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".GeneralFragment">
<ListView
android:id="#+id/listViewGeneral"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
And your row layout you can simplify like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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="wrap_content">
<TextView
android:id="#+id/textView_listview_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginTop="#dimen/_4sdp"
android:text="TextView"
android:textAlignment="center"
android:textSize="#dimen/_18ssp"
android:gravity="center"
android:layout_gravity="center_vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
But in my opinion it is better to define exact height of your item row, for example 48dp. In this case your layout will be more predictable.
You could modify as below:
<ListView
android:id="#+id/listViewGeneral"
android:layout_width="match_parent"
android:layout_height="match_parent" /> //notice this line
As you can see the custom layout is at the right and after some research I found that the blank space is reserved for icon and text of item. Is there a way to remove that blank space and align the custom layout to the left?
I am using menu to fill the navigation view as shown below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.NavigationView
android:id="#+id/nav1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/nav_drawer_items"
app:itemBackground="#color/app_bg_color"
app:itemIconTint="#color/text_white"
app:itemTextColor="#color/text_white"
android:background="#color/bottom_navigation_color"
android:fitsSystemWindows="true"
android:theme="#style/NavigationView" />
</android.support.v4.widget.DrawerLayout>
nav_drawer_items
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/tabs"
android:title="MAIN">
<menu>
<item
android:id="#+id/nav_highlights"
android:icon="#drawable/icon_home"
android:title="#string/nav_home"
android:checkable="true"/>
<item
android:id="#+id/nav_movies"
android:icon="#drawable/icon_movie"
android:title="#string/nav_movies"
android:checkable="true"/>
<item
android:id="#+id/nav_originals"
android:icon="#drawable/icon_original"
android:title="#string/nav_originals"
android:checkable="true"/>
<item
android:id="#+id/nav_live_tv"
android:icon="#drawable/icon_live"
android:title="#string/nav_live_tv"
android:checkable="true"/>
</menu>
</item>
<item
android:id="#+id/support"
android:title="SUPPORT">
<menu>
<item
android:id="#+id/nav_about_us"
android:icon="#drawable/icon_about"
android:title="#string/nav_about_us"
android:checkable="true"/>
<item
android:id="#+id/nav_feedback"
android:icon="#drawable/icon_feedback"
android:title="#string/nav_feedback"
android:checkable="true"/>
<item
android:id="#+id/nav_setting"
android:icon="#drawable/icon_setting"
android:title="#string/nav_setting"
android:checkable="true"/>
<item
android:id="#+id/nav_logout"
android:icon="#drawable/icon_logout"
android:title="#string/nav_logout"
android:checkable="true"/>
</menu>
</item>
<item
android:id="#+id/connect_us"
android:title="Connect with us">
<menu>
<item
android:id="#+id/social_items"
android:checkable="true"
app:showAsAction="always"
android:title=""
app:actionLayout="#layout/connect_us"/>
</menu>
</item>
</menu>
In menu you can see that I am using a layout using app:actionLayout in last item. Here is the connect_us.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/app_bg_color"
android:orientation="horizontal"
android:gravity="start">
<ImageView
android:id="#+id/connect_youtube"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/youtube_icon"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:padding="5dp" />
<ImageView
android:id="#+id/connect_facebook"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/facebook_icon"
android:padding="5dp"/>
<ImageView
android:id="#+id/connect_twitter"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/twitter_icon"
android:padding="5dp"/>
</LinearLayout>
Change your code according to my , its working . Take RelativeLayout as parent (only change with your connect_us.xml):
connect_us.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFFFFF"
android:gravity="left">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/connect_youtube"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#mipmap/ic_launcher"
android:padding="5dp" />
<ImageView
android:id="#+id/connect_facebook"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#mipmap/ic_launcher"
android:padding="5dp"/>
<ImageView
android:id="#+id/connect_twitter"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#mipmap/ic_launcher"
android:padding="5dp"/>
</LinearLayout>
</RelativeLayout>
Second Solution :
In your main_activity.xml (fix the width of the Navigation drawer)
I used here
android.support.design.widget.NavigationView to android:layout_width="320dp" I know its not a proper solution to fix layout_width.
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"
/>
And connect_us.xml layout also set the layout_width = "320dp"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320dp"
android:layout_height="match_parent"
android:background="#color/app_bg_color"
android:orientation="horizontal"
android:gravity="start">
<ImageView
android:id="#+id/connect_youtube"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/youtube_icon"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:padding="5dp" />
<ImageView
android:id="#+id/connect_facebook"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/facebook_icon"
android:padding="5dp"/>
<ImageView
android:id="#+id/connect_twitter"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/twitter_icon"
android:padding="5dp"/>
</LinearLayout>
Try adding your navigation view and Custom Layout (connect_us) inside a NestedScrollView as below:-
<android.support.v4.widget.DrawerLayout
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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.NavigationView
android:id="#+id/nav1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="#color/bottom_navigation_color"
android:fitsSystemWindows="true"
android:theme="#style/NavigationView"
app:headerLayout="#layout/nav_header"
app:itemBackground="#color/app_bg_color"
app:itemIconTint="#color/text_white"
app:itemTextColor="#color/text_white"
app:menu="#menu/nav_drawer_items" />
<include
android:id="#+id/footer_layout"
layout="#layout/connect_us"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.DrawerLayout>
Also, make sure to disable Nested Scrolling of NavigationView's child as below:-
ViewCompat.setNestedScrollingEnabled(navigationView.getChildAt(0), false);
I got a solution for this use recyclerview and inside your navigation view and add your views to recyclerview and create your adapter :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/my"
layout="#layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rvNavMenu"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="7"
android:overScrollMode="never" />
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
I am trying to make a custom Navigation Drawer with images and title underneath, like in the following image;
So this is my layout I named: menu_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<ImageView
android:id="#+id/img_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/menu_icon"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Menu Title"
android:gravity="center"
android:textSize="16dp"
android:textColor="#color/white"
android:layout_below="#+id/img_menu"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/colorPrimaryDark"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
and finally the menu; activity_main_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/nav_profile"
app:actionLayout="#layout/menu_item"/>
</menu>
The result I get is missing the TextView, what could be the issue here?
my result:
Thanks
use simple LinearLayout and apply android:gravity="center" to the root layout. also remove parent margin android:layout_margin="10dp"
the textview is out of the viewport in menu items
try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/img_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu Title"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
I want to change the default background image of my navigation drawer.
I have a .jpg image (1600x900) in drawable folder. I set android:background="#drawable/bg_1" for LinearLayout, but when i debug the app in my device, the image doesn't appear and i have a white background.
This is my nav_header_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="#+id/AccountInformation"
android:layout_width="match_parent"
android:layout_height="#dimen/nav_header_height"
android:background="#drawable/bg_1"
android:gravity="bottom"
android:orientation="vertical"
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:theme="#style/ThemeOverlay.AppCompat.Dark"
android:weightSum="1">
<ImageView
android:id="#+id/imageView"
android:layout_width="70dp"
android:layout_height="60dp"
android:layout_weight="0.3"
android:paddingTop="#dimen/nav_header_vertical_spacing"
app:srcCompat="#drawable/contatti" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing">
<Spinner
android:id="#+id/AccountSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/AccountEmail"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/AccountName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android Studio"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"/>
<TextView
android:id="#+id/AccountEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text="android.studio#android.com" />
</RelativeLayout>
</LinearLayout>
And this is the layout of the activity (activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
The attibute android:background="#drawable/bg_1" should be in the NavigationView view not the LinearLayout ViewGroup.
Hope this help.
You are doing it wrong.
See you have to apply the following:
android:background="#drawable/bg_1"
to NavigationView block in the other xml file
not to linearLayout which you include as Header Layout in the navigationView
Please try a .png image for that,
or after that check a color code android:background="#651FFF".
Hope this help.
Is there a way, using the NavigationView element of the Google support library, to use elevation on the items inside a NavigationView to achieve something like this:
You can see that the header of the navigation drawer has an elevation, like the footer on the bottom of the view.
I tried to use the "android:elevation" attribute but it seems to not work properly.
Here's my code for the NavigationView at the moment:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="end">
<include
layout="#layout/app_bar_product_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_filters">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center|end"
android:padding="16dp"
android:elevation="16dp"
android:orientation="horizontal"
tools:targetApi="lollipop">
<TextView
android:textAppearance="#style/TextAppearance.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"/>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Here's the XML file for the header of the navigation view:
<?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="wrap_content"
android:background="#color/colorAccent"
android:elevation="8dp"
android:gravity="bottom"
android:orientation="vertical"
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:theme="#style/ThemeOverlay.AppCompat.Light"
tools:targetApi="lollipop">
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="#dimen/status_cheat" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ordina_per"
android:textAppearance="#style/TextAppearance.AppCompat.Subhead"
android:textColor="#android:color/white" />
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/spinner_orders"
style="#style/SpinnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
As you see elevation doesn't work in this case. How can I solve this?
Give the root layout of your header layout a layout_marginBottom so that it can get some room to display the elevation shadow.
Like this:
android:layout_marginBottom="8dp"
android:elevation="4dp"