Custom Button not displaying inside Layout (RelativeLayout and LinearLayout) - android

I've created three drawables for my custom button as shown in the code snippets below
custom_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/button_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/button_default" />
</selector>
button_default.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff" />
<stroke
android:color="#f71b5d"
android:width="0.5dp" />
<corners
android:bottomLeftRadius="5dp"
android:topRightRadius="5dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
button_pressed.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ebc2ce" />
<stroke
android:color="#f71b5d"
android:width="0.5dp" />
<corners
android:bottomLeftRadius="5dp"
android:topRightRadius="5dp" />
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />
</shape>
Here is the parent layout where I'm trying to use these drawables to create a custom button. The custom button is inside the LinearLayout
fancy_card.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_gravity="center"
android:clickable="true"
card_view:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/fancy_card_bg">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_button"/>
</LinearLayout>
</android.support.v7.widget.CardView>
My problem: The button inside the LinearLayout does not show up but when I remove my custom drawable from the background of the button, (android:background="#drawable/custom_button"), I can now see the button. If I remove the button from the LinearLayout and apply my custom_button drawable background to it, it works. I'm really confused of what is going on here.

Give an ID to the Button and define button background in your java file.
btn.setBackgroundResource(R.drawable.custom_button);

Related

Edittext as spinner

I have a editext which I would like to show as drop down. SO for that I have background.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<solid android:color="#ffffff" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
<item>
<bitmap android:gravity="right" android:src="#drawable/ic_arrow_drop_down" />
</item>
</layer-list>
</item>
</selector>
And added that as background for my edittext. This is what I get:
As you can see there is slight gap between the image and editext border. I would like to make my edittext like this:
How can I achieve this?
Try this
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg"
android:orientation="horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:background="#drawable/bgnew"
android:src="#drawable/ic_android_black_24dp" />
</LinearLayout>
</LinearLayout>
Create bg.xml like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Background Color -->
<solid android:color="#ffffff" />
<!-- Border Color -->
<stroke android:width="1dp" android:color="#ff9900" />
</shape>
create a bgnew.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Background Color -->
<solid android:color="#ffffff" />
<!-- Border Color -->
<stroke android:width="1dp" android:color="#color/colorAccent" />
</shape>
Output
Create a RelativeLayout with EditText and ImageView UI Components :).
Don't complicate yourself.
Just try Linear layout with layout orientation horizontal of EditText and ImageView. It is simple.

Android: selectableItemBackground not working on button with xml drawable

I made a rounded button with xml drawable and applied android:foreground="?attr/selectableItemBackground" in hope of getting a ripple effect. However, ripple effect does not work. Is there anyway to make the ripple effect work? As a workaround I wrapped the button with a FrameLayout and applied android:foreground="?attr/selectableItemBackground" to it, but in that case the ripple is rectangular and goes beyond button (as it is rounded).
xml:
<Button
android:id="#+id/reg_next"
android:layout_width="125dp"
android:layout_height="40dp"
android:text="#string/next"
android:layout_gravity="center"
android:textAllCaps="false"
android:textColor="#color/colorPrimary"
android:textSize="18sp"
android:background="#drawable/rounded_button_background"
android:foreground="?attr/selectableItemBackground"/>
rounded_button_background:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#ebeff1"/> <!-- this one is ths color of the Rounded Button -->
<stroke android:width="1px" android:color="#979797" />
<corners
android:radius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
</shape>
You need to create ripple drawable and set it as button background (without foreground attribute):
rounded_button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#2793c9">
<item>
<shape
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#ebeff1" /> <!-- this one is ths color of the Rounded Button -->
<stroke
android:width="1px"
android:color="#979797" />
<corners
android:bottomLeftRadius="20dp"
android:radius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>
</item>
</ripple>
If you want support api bellow 21 (without ripple effect), add this drawable to directory drawable-v21 and in directory drawable create these files:
rounded_btn_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#ebeff1" /> <!-- this one is ths color of the Rounded Button -->
<stroke
android:width="1px"
android:color="#979797" />
<corners
android:bottomLeftRadius="20dp"
android:radius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>
rounded_btn_active.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#2793c9" /> <!-- this one is ths color of the Rounded Button -->
<stroke
android:width="1px"
android:color="#979797" />
<corners
android:bottomLeftRadius="20dp"
android:radius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>
rounded_button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/rounded_btn_active" android:state_enabled="true" android:state_pressed="true" />
<item android:drawable="#drawable/rounded_btn_normal" android:state_enabled="true" />
</selector>

Ripple effect on shape drawable

Trying to do something really simple here and have looked up a bunch of SO resource, but to no avail. I am trying to get the ripple effect on a button which uses a drawable background of type of shape drawable. The relevant files:
background_button:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1px"
android:color="#80ffffff" />
<solid android:color="#android:color/transparent" />
</shape>
ripple.xml within the drawable-v21 folder:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:drawable="#drawable/background_button"/>
</ripple>
Button.xml:
<Button
android:id="#+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:background="#drawable/ripple"
/>
What is wrong here.
Thanks!
My advice would be not to use <ripple tag. I have 2 reasons: it is not that easy to do exactly what you want and you have to 2 different .xml files for every background. I don't like to have drawable-v21 folder.
My solution is to wrap your Button with FrameLayout and use android:foreground attribute. This way you can have whatever background you want and you can keep the ripple effect.
<FrameLayout
android:id="#+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:foreground="?attr/selectableItemBackground">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_button"/>
</FrameLayout>
Notice that I moved all the attributes and the id to FrameLayout. You should set onClickListener to FrameLayout instead of the Button.
Btw, ?attr/selectableItemBackground is great. Use it as much as possible. It replaces blue Holo color with gray for old devices from Android 4.0 to 4.3.
Try this.
ripple_effect.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#2797e0"
tools:targetApi="lollipop">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#2797e0" />
</shape>
</item>
button.xml
<Button
android:id="#+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:background="#drawable/ripple_effect"/>
build.gradle
compile 'com.android.support:appcompat-v7:23.1.1'
More simple solution - to use this drawable-xml as value of property "android:background" of the Button:
drawable/bkg_ripple.xml:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:drawable="?attr/colorPrimary"/>
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
</ripple>
button.xml:
<Button
android:id="#+id/mybutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
android:background="#drawable/bkg_ripple"
/>
I had the similar task. Let me explain how i solve it. It outputs circle imageViews with shadow and ripple effect not goes beyond circle boundaries.
<ImageView
android:id="#+id/iv_undo"
android:layout_width="#dimen/iv_width_altmenu"
android:layout_height="#dimen/iv_height_altmenu"
android:src="#drawable/undo"
android:elevation="#dimen/elevation_buttons"
android:foreground="#drawable/ripple_effect"
android:background="#drawable/buttons_inactive_coloring"
/>
The following provides ripple effect:
android:foreground="#drawable/ripple_effect"
The following provides circle imageView.
android:background="#drawable/buttons_inactive_coloring"
The following provides shadow:
android:foreground="#drawable/ripple_effect"
Another problem you may be probably face is ripple effect goes out of circle boundaries. In order to solve, use following file(ripple_effect.xml)
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#color/button_active"
tools:targetApi="lollipop">
<item android:id="#android:id/mask">
<shape android:shape="oval">
<solid android:color="#color/button_active" />
</shape>
</item>
</ripple>
If you do not use the following :
<item android:id="#android:id/mask">
<shape android:shape="oval">
<solid android:color="#color/button_active" />
</shape>
</item>
ripple effect goes beyond circle boundaries and this does not looks nice. Be careful and takes it easy.
That works for me
drawable/rect.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/listview_background_shape">
<stroke android:width="1dp" android:color="#FF4C71F5" />
<padding android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
<corners android:radius="5dp" />
<solid android:color="#00000000" />
</shape>
and for ripple drawable/rip.xml:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#f816a463"
tools:targetApi="lollipop">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#f816a463" />
</shape>
</item>
</ripple>
and for your button
<Button
android:id="#+id/nm"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/rect"
android:enabled="true"
android:text="#string/vnm"
android:textColor="#color/colorpr"
android:textStyle="bold"
android:foreground="#drawable/rip"/>
Hope this helps!
This work for me..
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#color/smooth_white"
tools:targetApi="lollipop">
<item android:drawable="#drawable/button_green_background" />
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#color/smooth_white" />
</shape>
</item>
</ripple>
The point is section
<item android:drawable="#drawable/button_green_background" />
Try this:
card_back.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="?attr/cardBGColor" />
<stroke android:width="1dp" android:color="?attr/borderColor"/>
</shape>
</item>
</selector>
card_ripple.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#bbb">
<item android:drawable="#drawable/card_back" />
</ripple>
And setup it this way: android:background="#drawable/card_ripple"
Quick solution
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#color/blue"
tools:targetApi="lollipop">
<item
android:id="#android:id/mask"
tools:targetApi="lollipop">
<shape android:shape="rectangle">
<solid android:color="#color/blue" />
<corners android:radius="5dp" />
</shape>
</item>
<item android:id="#android:id/background">
<shape android:shape="rectangle">
<stroke
android:width="0.1dp"
android:color="#312D2D" />
<solid android:color="#FFF" />
<corners android:radius="50dp" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
</ripple>
This will help
<com.abcd.ripplebutton.widget.RippleButton
android:id="#+id/Summit"
android:layout_width="260dp"
android:layout_height="50dp"
android:text="Login"
android:textColor="#color/white"
android:textStyle="bold"
app:buttonColor="#color/Button"
app:rippleColor="#color/white" />
For more See this
For me only this work
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#cccccc">
<item android:id="#android:id/background">
<shape android:shape="rectangle">
<solid android:color="#android:color/white" />
</shape>
</item>
</ripple>
And in layout
<?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="match_parent"
android:clickable="true"
android:background="#drawable/ripple_white"/>
Yes, it should be clickable

How to set background to edittext in android?

I am using custom drawable to set background of edit text.Following is the code for edit text background
<?xml version="1.0" encoding="utf-8"?>
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#595C65" />
<solid android:color="#ffffff" />
It displays the edit box with rectangle background .But i want to set edit text background with L shape(set left and bottom backgrounds).
Without using external images and i want to set these background via drawable xmls.
Expected output:
Current output:
I found a solution for these:
text.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:bottom="3px" android:left="3px">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
main.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="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:background="#drawable/text"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="30dp"
android:ems="10"
android:gravity="center_horizontal"
android:padding="2dp"
android:password="true" />
</RelativeLayout>
Expected Output:
Without using external images we can get a output with the help of drawable text.xml
Using a drawable this should work :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#555555" />
</shape>

How to create Google + cards UI in a list view?

I want to create a listView of cards, but after reading this blog post goolge-plus-layout, I'm cards are a viable solution for a list of anything. The animation part seems too memory intensive to load say a listview with more than 40 elements simultaneously.
Is there a better way to achieve a cards UI in listView?
You can create a custom drawable, and apply that to each of your listview elements.
I use this one for cards in my UI. I don't think there is significant performance issues with this approach.
The drawable code (in drawable\big_card.xml) looks like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#color/second_grey" />
</shape>
</item>
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape android:shape="rectangle" >
<corners android:radius="3dp" />
<solid android:color="#color/card_shadow" />
</shape>
</item>
<item
android:bottom="12dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape android:shape="rectangle" >
<corners android:radius="3dp" />
<solid android:color="#color/card_white" />
</shape>
</item>
</layer-list>
I apply the background to my listview elements like this:
<ListView
android:id="#+id/apps_fragment_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="#drawable/big_card" />
If you want to add this as a background to any View (not just a list), you just make the custom drawable that View's background element:
<TextView
android:id="#+id/any_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/big_card" />
EDIT: Google provides a nice class called CardView. I didn't check it but it looks promising.
Here's the previous way, which also works fine (that's what I wrote before the edit) :
There is a nice tutorial here and a nice sample of it here .
in short , these are the files you can create:
listView definition:
android:divider="#null"
android:dividerHeight="10dp"
android:listSelector="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
android:headerDividersEnabled="true"
android:footerDividersEnabled="true"
also this:
m_list.addHeaderView(new View(this));
m_list.addFooterView(new View(this));
res/drawable/selector_card_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#drawable/layer_card_background_selected" />
<item android:drawable="#drawable/layer_card_background" />
</selector>
listView item :
res/layout/list_item_card.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:descendantFocusability="beforeDescendants">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:paddingRight="15dp"
android:background="#drawable/selector_card_background"
android:descendantFocusability="afterDescendants">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</FrameLayout>
res/drawable/layer_card_background_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CABBBBBB"/>
<corners android:radius="2dp" />
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#CCCCCC"/>
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>
res/drawable/layer_card_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CABBBBBB"/>
<corners android:radius="2dp" />
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>
If all you want is a ListView that simulates the cards-look you can use a 9-patch as background for your listitems to make them look like cards. You can find a 9-patch and some more tips and explanation here: http://www.tiemenschut.com/simply-get-cards-ui-look/
Add divider for the Listview item and padding :
android:divider="#android:color/transparent"
android:dividerHeight="1dip"
Add RelativeLayout into your LinearLayout for ListItem with some desired padding :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:padding="3dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rowshadow" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...
Add Background to the listview item , like :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape
android:shape="rectangle">
<solid android:color="#android:color/darker_gray" />
<corners android:radius="0dp"/>
</shape>
</item>
<item android:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="0dp"/>
</shape>
</item>
</layer-list>
Use https://github.com/elcrion/demo.cardlistview as an example. It is somehow close to google style
As "android developer" briefly mentions in his answer, the CardView class can be used to easily create card views.
Just wrap you UI widgets in a CardView element and you are ready to go. See the short introduction to the CardView widget at https://developer.android.com/training/material/lists-cards.html#CardView.
The CardView class requires a v7 support library, remember to add the dependencies to your .gradle file!
compile 'com.android.support:cardview-v7:21.0.+'

Categories

Resources