How to create such button with shadow:
I don't know how to modify this button drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<shape android:shape="rectangle">
<gradient android:angle="90" android:startColor="#0F9D58" android:endColor="#0F9D58" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:top="10dp" android:left="20dp" android:right="20dp" />
</shape>
</item>
Thanks!
UPDATE. Finally , the code should be as follows:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:left="5dp" android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#0F4858" />
</shape>
</item>
<item android:bottom="2dp" android:left="0dp" android:right="0dp">
<shape>
<gradient android:angle="270"
android:endColor="#0F9D58" android:startColor="#0F9D58" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
Read this thread
Basically, you need create a xml for your custom button, like:
button_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#D6D6D6" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270"
android:endColor="#E2E2E2" android:startColor="#BABABA" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
And now, you can use it, doing reference to the file with:
<Button
android:background="#drawable/button_selector"
...
..
/>
Related
trying to put shadow on button with transparent color.
trying with this selection.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<solid android:color="#00808080" />
<!-- <gradient
android:angle="315"
android:startColor="#1Acccccc"
android:endColor="#00cccccc"
android:type="linear"
/>-->
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<solid android:color="#10808080" />
<!--<gradient
android:angle="315"
android:startColor="#00cccccc"
android:endColor="#1Acccccc"
android:type="linear"
/>-->
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<!--<solid android:color="#20808080"/>-->
<gradient
android:angle="315"
android:endColor="#20808080"
android:startColor="#00cccccc"
android:type="linear" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<!--<solid android:color="#30808080"/>-->
<gradient
android:angle="315"
android:endColor="#30808080"
android:startColor="#00cccccc"
android:type="linear" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<!--<solid android:color="#50808080"/>-->
<gradient
android:angle="315"
android:endColor="#50808080"
android:startColor="#00cccccc"
android:type="linear" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
</shape>
</item>
<!-- Background -->
<item>
<shape>
<solid android:color="#80FFFFFF" />
<corners android:radius="0dp" />
</shape>
</item>
</layer-list>
i am using this code for shadow its work for me....!
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#D6D6D6" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270"
android:endColor="#E2E2E2" android:startColor="#BABABA" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
As I understood, you need something 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="#cabababa"/>
<corners android:radius="2dp"/>
</shape>
</item>
<item
android:left="0dp"
android:right="2dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="0dp" />
</shape>
</item>
</layer-list>
Here i want to ask a simple question that make me so confuse,
i have developing an android app that i want to use material design theme.
But when i try to code the Shadow under the RaisedButton, it's doesn't work.
I mean it just make a stroke around the button and not the shadow.
Please master, help me is there any simple way to make this shadow??
Thanks
NB. This is my custon_button.xml
<item android:state_pressed="true" >
<shape>
<solid
android:color="#color/solidpress"
/>
<stroke
android:width="1dp"
android:color="#color/strokepress" />
<corners
android:radius="2dp" />
<padding
android:left="5dp"
android:top="10dp"
android:right="1dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true" > //focused fuck shit man
<shape>
<solid
android:color="#color/solidfocus"
/>
<stroke
android:width="3dp"
android:color="#color/strokefocus" />
<corners
android:radius="2dp" />
<padding
android:left="5dp"
android:top="10dp"
android:right="5dp"
android:bottom="10dp" />
</shape>
</item>
<item> // normal
<shape>
<solid
android:color="#color/solidnormal" />
<stroke
android:width="1dp"
android:color="#color/strokenormal" />
<corners
android:radius="2dp" />
<padding
android:left="5dp"
android:top="10dp"
android:right="1dp"
android:bottom="10dp" />
</shape>
</item>
and i apply that code to my activity with
android:background="#drawable/custom_button
Please look this
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"><layer-list>
<item><shape>
<gradient android:angle="270" android:centerColor="#00c0f0" android:endColor="#036b86" android:startColor="#01bff3"></gradient>
<corners android:radius="5dp" />
</shape></item>
<item android:bottom="3dp"><shape>
<gradient android:angle="270" android:centerColor="#00c0f0" android:endColor="#01bff3" android:startColor="#01bff3"></gradient>
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
<corners android:radius="5dp" />
</shape></item>
</layer-list></item>
<item android:state_pressed="true"><layer-list>
<item ><shape>
<gradient android:angle="270" android:centerColor="#00c0f0" android:endColor="#01bff3" android:startColor="#036b86"></gradient>
<corners android:radius="5dp" />
</shape></item>
<item android:top="3dp"><shape>
<gradient android:angle="270" android:centerColor="#00c0f0" android:endColor="#01bff3" android:startColor="#01bff3"></gradient>
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
<corners android:radius="5dp" />
</shape></item>
</layer-list></item>
</selector>
If rajan ks' answer does't work, you can try wrapping the button in a CardView (android.support.v7.widget.CardView), and give the CardView some elevation using its app:cardElevation attribute.
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="4dp"
app:cardPreventCornerOverlap="false">
<Button />
</android.support.v7.widget.CardView>
shadow.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#D6D6D6" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270"
android:endColor="#E2E2E2" android:startColor="#BABABA" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
and Add this code to your Button
android:background="#drawable/shadow"
Have a look at this for Material Kind of Shadow: Shadow Background Android
I am trying to create a glow effect by using a gradient.
In my XML I have this...
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#7AD8FF" />
<gradient android:startColor="#android:color/transparent" android:endColor="#7AD8FF" android:type="radial"/>
<stroke android:width="0dp" android:color="#7AD8FF"/>
<corners android:radius="20dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="#android:color/transparent"/>
<stroke android:width="0dp" android:color="#D1D1D1" />
<corners android:radius="0dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
When I try to set "android:type="radial"", it causes an error...
...Any ideas?
Try specifying android:gradientRadius:
<gradient
android:startColor="#android:color/transparent"
android:endColor="#7AD8FF"
android:type="radial"
android:gradientRadius="100"
/>
I do have a group of buttons, which I am customizing using selector-shape. Here is the code and image of what i have so far:
CODE-bgbtn.xml
<item android:state_pressed="true" >
<shape>
<solid
android:color="#004dfd" />
<stroke
android:width="1dp"
android:color="#2f3436" />
<corners
android:radius="0dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#425262"
android:endColor="#51677d"
android:angle="45" />
<stroke
android:width="1dp"
android:color="#2f3436" />
<corners
android:radius="0dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
And the results of this:
I have applied the style only for first button, as you can see it looks too flat. How to make it look more as a button?
Try this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:state_pressed="true">
<shape android:padding="10dp" android:shape="rectangle">
<gradient android:startColor="#color/yourColor" android:endColor="#color/yourColor" android:angle="90"/>
<stroke android:width="2dp" android:color="#3E4976" />
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
<item android:state_enabled="true" android:state_focused="true">
<shape android:padding="10dp" android:shape="rectangle">
<gradient android:startColor="#color/yourColor" android:endColor="#color/yourColor" android:angle="90"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
<item android:state_enabled="true">
<shape android:padding="10dp"
android:shape="rectangle">
<gradient android:startColor="#color/yourColor" android:endColor="#color/yourColor" android:angle="90"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
</selector>
And then setBackground for button
android:background="#drawable/custom_button"
I have some troubles managing Android State List for a button. I specified some Shape drwable item for different states, but i also need to change textColor depending on the current state.
My actual state list xml is:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient
android:startColor="#color/white"
android:endColor="#color/light_gray"
android:angle="270" />
<stroke
android:width="3dp"
android:color="#color/classic_red1" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#color/classic_red1"
android:endColor="#color/classic_red2"
android:angle="270" />
<stroke
android:width="2dp"
android:color="#color/white" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
I need also to change textColor based on these 2 states.
Thanks in advance.
selector for the button BG:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient
android:startColor="#color/white"
android:endColor="#color/light_gray"
android:angle="270" />
<stroke
android:width="3dp"
android:color="#color/classic_red1" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<solid android:color="#424242" /> //another custom shape here for focus state
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#color/classic_red1"
android:endColor="#color/classic_red2"
android:angle="270" />
<stroke
android:width="2dp"
android:color="#color/white" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
selector for the button text color:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#color/white" /> <!-- pressed -->
<item android:color="#color/black" /> <!-- default/unchecked -->
</selector>