How To Create A Rounded Corners Button With Gradient
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item>
<!-- below code is used to create gradient with shape rectangle --> <shape android:shape="rectangle"> <gradient android:centerColor="#77C296" android:endColor="#4EA99F" android:startColor="#4EA99F"/> <corners android:radius="30dp"/> </shape> </item> <!--CODE TO SET BACKGROUND COLOR-->
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape android:shape="rectangle" >
<solid android:color="#1A1F29" />
<corners android:radius="30dp"/>
</shape>
</item> </layer-list>
2. Set it as background in button or any view where want to have that effect
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:background="#1A1F29"
android:layout_height="match_parent"> <Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:textColor="#ffffff"
android:background="@drawable/gradient_background"
android:padding="20dp"
android:text="Sign Up"
app:layout_constraintEnd_toStartOf="@+id/guideline2"
app:layout_constraintStart_toStartOf="@+id/guideline"
tools:layout_editor_absoluteY="259dp" /> <android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.2" /> <android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.8" />
</android.support.constraint.ConstraintLayout>
No comments :
Post a Comment