Reputation: 69
<Button
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:background="@drawable/rounded_corner2"
android:onClick="signin"
android:text="SIGN IN"
android:textColor="#fff"
/>
xml files: custom_bg.xml
<?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="@color/colorHighlight"></solid>
</shape>
</item>
<item>
<shape>
<solid android:color="@android:color/white"></solid>
</shape>
</item>
</selector>
rounded_corner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- view background color -->
<solid
android:color="#c62828">
</solid>
<!-- view border color and width -->
<stroke
android:width="3dp"
android:color="#ccc">
</stroke>
<!-- If you want to add some padding -->
<padding
android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp">
</padding>
<!-- Here is the corner radius -->
<corners
android:radius="10dp">
</corners>
</shape>
How can I use these two xml files in my Button View as an android:background
property?
Upvotes: 1
Views: 2408
Reputation: 21
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/grren_button" />
<item android:drawable="@drawable/tv_background"/>
<Button
android:id="@+id/signup_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/password_signup"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:background="@drawable/layer1"
android:gravity="center"
android:text="Sign up"
android:textColor="@color/white"
android:textSize="15sp"
>
</Button>
Upvotes: 2
Reputation: 20211
Use a layer-list
:
combined.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/custom_bg" />
<item android:drawable="@drawable/rounded_corner"/>
</layer-list>
Note: you can also combine everything into one file by moving everything between the <item>
tags instead of using the android:drawable
property.
Upvotes: 0