I want to make a button like this. I used cardview to give the radius and drop shadow effect. But only dropshadow does not gives an edgy style like in the image above.
Here is my code for creating this type of button:
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
app:cardCornerRadius="20dp"
app:cardBackgroundColor="#color/tuna2"
app:strokeColor="#color/gun_powder"
app:cardElevation="6dp"
app:contentPadding="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/transfer"
android:textColor="#color/white"
android:layout_marginStart="30dp"
android:layout_marginEnd="37dp"
android:fontFamily="#font/dm_sans"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
app:layout_constraintBottom_toBottomOf="#+id/textView28"
app:layout_constraintStart_toEndOf="#+id/textView28"
app:layout_constraintTop_toTopOf="#+id/textView28"
app:srcCompat="#drawable/ic_arrow_right" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
This code creates a button like in the image below:
How can I make the button look like the sun is hitting from above?
Try This
drawable/custom_bg.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="#41445F"/>
<corners android:radius="20dp"/>
<size android:width="100dp" android:height="40dp"/>
</shape>
</item>
<item android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#303348"/>
<corners android:radius="20dp"/>
<size android:width="100dp" android:height="40dp"/>
</shape>
</item>
</layer-list>
and set background in ConstraintLayout layout like this
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/custom_bg">
output like this
Related
I am working on a tv remote application in that i have to create this type of user interface(ignore the red dashed line) i tried using a circle background that is
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="oval">
<solid
android:color="#color/colorGreyShade2"/>
<padding
android:bottom="#dimen/_40sdp"
android:left="#dimen/_40sdp"
android:right="#dimen/_40sdp"
android:top="#dimen/_40sdp"/>
<stroke
android:width="1dp"
android:color="#color/colorGreyShade2"/>
</shape>
</item>
<item>
<shape
android:shape="oval">
<solid
android:color="#color/colorGreyShade2"/>
<size
android:width="#dimen/_100sdp"
android:height="#dimen/_100sdp"/>
<stroke
android:width="1dp"
android:color="#color/colorGreyShade1"/>
</shape>
</item>
</layer-list>
and using this as background of a layout and trying to adjust the navigation buttons in that but not able to achieve.
Can i use this image in an ImageView and detect user clicks from five button areas?
You can achieve this from this. no need create drawable layer list. You can use imageview, textview and constraint layout.And this will also easy to implement all five button clicks.
bg_circle_fill_white.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/divider" />
<stroke
android:width="1dp"
android:color="#color/black" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="#dimen/_100sdp" />
</shape>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="#dimen/_200sdp"
android:layout_height="#dimen/_200sdp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="#dimen/_150sdp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#drawable/bg_circle_fill_white"
android:layout_height="#dimen/_150sdp">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:src="#drawable/ic_previous_arrow"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:padding="#dimen/_5sdp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content" />
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:src="#drawable/ic_next_arrow"
app:layout_constraintEnd_toEndOf="parent"
android:padding="#dimen/_5sdp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content" />
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:src="#drawable/ic_arrow_up"
app:layout_constraintEnd_toEndOf="parent"
android:padding="#dimen/_5sdp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_height="wrap_content" />
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:src="#drawable/ic_arrow_down"
app:layout_constraintEnd_toEndOf="parent"
android:padding="#dimen/_5sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_height="wrap_content" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/_20sdp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="OK"
android:background="#drawable/bg_circle_fill_white" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I have a Textview on which I am trying to add rounded corners on.
My TextView:
<TextView
android:id="#+id/textview_answer_one"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="#drawable/rounded_corners"
android:elevation="4dp"
android:gravity="center"
android:text=""
app:layout_constraintBottom_toTopOf="#+id/guideline5"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline" />
and my Drawable file:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="15dp" />
<solid android:color="#ffffff"/>
</shape>
</item>
</layer-list>
When I check in the XML Editor (I don't know what it's called) in Android Studio, you can clearly see that the TextView have rounded corners. However, when I run the app on my phone the TextView does not have rounded corners. How come? Any suggestions on what I might be doing wrong?
Try This Shape :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<solid android:color="#CCCCCC"/>
</shape>
Example Xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TextView
android:background="#drawable/r"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text View"
android:textSize="20dp"
android:textColor="#FFFFFF"
android:gravity="center_horizontal"
/>
</LinearLayout>
I have been trying to achieve button like in attached image & for that I have created gradient SVG with shadow so that it looks like elevation but when this svg applied to button as background drawable it looks flat & ripple effect is also gone.
I want to achieve same button as below image :
And here is my code :
<Button
android:id="#+id/btn_login"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="35dp"
android:enabled="false"
android:elevation="10dp"
android:translationZ="10dp"
android:stateListAnimator="#null"
android:background="#drawable/bg_gradient"
android:text="#string/btn_txt_login"
android:textColor="#android:color/white"
android:textSize="18sp" />
I'm using SVG file for creating background gradient with rounded border. Any help would be appreciated.
I have a solution for you.
Add this into your build.gradle(Module:app) dependency:
implementation 'com.android.support:cardview-v7:27.1.1'
Now use CardView layout instead of Button:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center_vertical|center_horizontal"
android:textSize="18sp"
android:text="LOGIN"
android:textColor="#android:color/white"
android:textStyle="bold"
android:background="#drawable/gradient"/>
</android.support.v7.widget.CardView>
Create gradient.xml file into drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#8b0ab7"
android:endColor="#0b85d0"
android:angle="0"/>
<corners android:radius="10dp"/>
</shape>
Add these attributes, if still it doesn't work use cardview
android:clipChildren="false"
android:clipToPadding="false"
and here is your code
<Button android:id="#+id/btn_login"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="35dp"
android:enabled="false"
android:elevation="10dp"
android:translationZ="10dp"
android:stateListAnimator="#null"
android:clipChildren="false"
android:clipToPadding="false"
android:background="#drawable/bg_gradient"
android:text="#string/btn_txt_login"
android:textColor="#android:color/white"
android:textSize="18sp" />
Please try with using the following drawable content.
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/colorDefaultButtonRipple">
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/darker_gray" />
<corners android:radius="15dp" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="0" android:endColor="#5789bc" android:startColor="#8e6fa6" />
<corners android:radius="15dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</ripple>
I need to add a shadow to a Button with these attributes "from zeplin":
and this is the design
I tried this code
<Button
android:id="#+id/btn_sign_in"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="35dp"
android:background="#drawable/auth_button_shape"
android:shadowColor="#41ff4800"
android:shadowDx="0"
android:shadowDy="8"
android:text="#string/sign_in"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="14sp" />
auth_button_shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ff7c44" />
<corners android:radius="100dp" />
</shape>
But not worked and the other attributes "Blur" and "Spread" How I can set them for the button.
Thanks.
Thanks to Taras I have solution. You can use this library for creating colored shadow to button. Just place your view element inside shadow layout. Of course basic layout is ConstraintLayout.
Some pieces of code for example
<com.gigamole.library.ShadowLayout
android:id="#+id/shadowLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:sl_shadow_angle="90"
app:sl_shadow_color="#color/light_orange_color"
app:sl_shadow_distance="2dp"
app:sl_shadow_radius="7dp"
app:sl_shadowed="true">
<ImageView
android:id="#+id/ivYourImageName"
android:layout_width="144dp"
android:layout_height="44dp"
android:background="#drawable/button_shape"
android:foregroundGravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</com.gigamole.library.ShadowLayout>
Button shape :
<?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="2dp" />
<gradient android:angle="180" android:endColor="#ffc349" android:startColor="#ff8006" />
</shape>
</item>
</selector>
Result:
you need to add this line of code inside button tag
android:stateListAnimator="#null"
because button override any evelation value you set by passing null to android:stateListAnimator it will remove stateList attrs
for color you can add this line to show colored shadow
android:outlineSpotShadowColor="#303030"
check answer
Android elevation not showing shadow on Button
use AppCompatButton instead of Button,use elevation and use android:backgroundTint for button colour.
<android.support.v7.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sign_in"
android:backgroundTint="#ccd3e0ea"
android:elevation="4dp"/>
output is,
bg_test.xml :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--the shadow comes from here-->
<item
android:bottom="-6dp"
android:drawable="#android:drawable/dialog_holo_light_frame"
android:left="-6dp"
android:right="-6dp"
android:top="-6dp">
</item>
<item
android:bottom="-6dp"
android:left="-6dp"
android:right="-6dp"
android:top="-6dp">
<shape android:shape="rectangle">
<solid android:color="#color/white" />
<stroke
android:width="#dimen/_1sdp"
android:color="#color/yellow" />
</shape>
</item>
</layer-list>
Activity.xml code:
<Button
android:layout_width="#dimen/_150sdp"
android:layout_height="48dp"
android:layout_marginTop="10dp"
android:text="#string/sign_In"
android:layout_marginLeft="#dimen/_80sdp"
android:layout_gravity="center"
android:textSize="14sp"
android:background="#drawable/bg_test" />
Design Button :
Is there a way to create these two boxes with XML only (beside the icon of course)
The tob box has rounded bordered around it and shadow but inside it divided to two parts which one is pink background and one is white background (without stroke between them)
Create 2 XML drawables
rect_colored.xml
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/colorAccent"/>
<corners android:bottomRightRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
rect_white.xml
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:color="#color/colorPrimaryDark"
android:width="2dp"/>
<corners android:radius="5dp"/>
</shape>
Position the drawables appropriately
This will work differently with different root views. I'm using ConstraintLayout for simplicity
<android.support.constraint.ConstraintLayout
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">
<FrameLayout
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:background="#drawable/rect_white"
android:id="#+id/frameLayout"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp">
<!--Content here-->
</FrameLayout>
<FrameLayout
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginBottom="0dp"
android:layout_marginRight="2dp"
android:layout_marginTop="0dp"
android:background="#drawable/rect_colored"
app:layout_constraintBottom_toBottomOf="#+id/frameLayout"
app:layout_constraintRight_toRightOf="#+id/frameLayout"
app:layout_constraintTop_toTopOf="#+id/frameLayout">
<!--Content here-->
</FrameLayout>
</android.support.constraint.ConstraintLayout>
The output
Just use a LayerList with the shapes you need nested. May take a little tweaking, but it is simple enough. You can even add in your bitmaps for the left icon if you like. Just make your layers, and adjust from the sides and handle your corners.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="50dp">
<shape
android:shape="rectangle" >
<solid android:color="#0000FF" />
<corners android:bottomRightRadius="20dp" android:topRightRadius="20dp" />
</shape>
</item>
<item android:right="50dp">
<shape
android:shape="rectangle" >
<solid android:color="#ffffff" />
<corners android:bottomLeftRadius="20dp" android:topLeftRadius="20dp" />
</shape>
</item>
</layer-list>
Here simply you create a one xml file & drawable file to create shape & border.
MyActivity.Xml
<LinearLayout
android:id="#+id/ll_mobile_img"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:paddingLeft="15dp"
android:paddingRight="15dp">
<RelativeLayout
android:id="#+id/rr_verification_code"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_weight="0.3">
<EditText
android:id="#+id/et_verification_code"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/ractangle_mobile_white_border"
android:ems="10"
android:hint="Enter Code"
android:drawableLeft="#mipmap/ic_launcher"
android:imeOptions="actionGo"
android:inputType="number|textAutoComplete"
android:maxLength="6"
android:paddingBottom="15dp"
android:paddingLeft="10dp"
android:paddingTop="16dp"
android:singleLine="true"
android:textColor="#android:color/white"
android:textColorHint="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/ll_country_img"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#android:color/white"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/tv_verification_code_img"
android:layout_width="38dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/globe"
android:textColor="#color/blue_font_color"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
Drawable:- ractangle_mobile_white_border.xml
[![<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<gradient android:angle="360" android:endColor="#android:color/transparent" android:startColor="#android:color/transparent" />
<stroke android:width="1dp" android:color="#android:color/white" />
<corners android:bottomRightRadius="1dp" android:topRightRadius="1dp"/>
<padding android:bottom="3dp" android:left="0dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
Hope this helps you.