Home
› Uncategorized
This exercise demonstrate how to create custom background, which can be applied on various views such as TextView, Button, ImageButton...etc.
Create /res/drawable/mybackground.xml to define our custom background.
Use the custom background in layout file.
Download the files.
Related:
- Create custom Button using StateListDrawable
Create /res/drawable/mybackground.xml to define our custom background.
<?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="#FF0000" android:endColor="#FF00FF" android:angle="180" /> <stroke android:width="3dp" android:color="@android:color/background_dark" /> <corners android:radius="3dp" /> <padding android:left="50dp" android:top="10dp" android:right="50dp" android:bottom="10dp" /> </shape> </item> <item android:state_focused="true" > <shape> <gradient android:startColor="@android:color/background_light" android:endColor="@android:color/background_dark" android:angle="180" /> <stroke android:width="3dp" android:color="@android:color/background_dark" /> <corners android:radius="3dp" /> <padding android:left="50dp" android:top="10dp" android:right="50dp" android:bottom="10dp" /> </shape> </item> <item> <shape> <gradient android:startColor="@android:color/background_light" android:endColor="@android:color/background_dark" android:angle="180" /> <stroke android:width="3dp" android:color="@android:color/background_dark" /> <corners android:radius="3dp" /> <padding android:left="50dp" android:top="10dp" android:right="50dp" android:bottom="10dp" /> </shape> </item> </selector>
Use the custom background in layout file.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, it's a TextView" android:clickable="true" android:background="@drawable/mybackground" android:layout_margin="5dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, it's a Button" android:background="@drawable/mybackground" android:layout_margin="5dp" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:background="@drawable/mybackground" android:layout_margin="5dp" /> </LinearLayout>

Related:
- Create custom Button using StateListDrawable
-- Delivered by Feed43 service
Related Posts
There is no other posts in this category.Popular
-
[Android] The Dark Knight Rises v1.1.1 APK by GameloftThe Dark Knight Rises is one of the hottest games just released by Gameloft in July 2012 on Androi…
-
The Avengers – Iron Man Mark VII 1.1 APKThe Avengers – Iron Man Mark VII 1.1 APK Suit up and Blast off in the First-Ever Fully-Interactive …
-
Angry Birds Space v1.0.1 for AndroidAngry Birds Space v1.0.1 for Android The #1 mobile game of all time blasts off into space! All new …
-
How To: Copy And Paste In Android Mobile'>The copy, cut, paste and select the features Android has many nuances. In this how-to, we will foc…
-
[Android] Battleloot Adventure HD v1.0.7 (apk + data)In Battleloot Adventure HD , let's roll out and your adventure is about to begin. In the kingdo…
-
[Android] Zuma's Revenge HD v1.0.8 Free Download [Mediafire]Zuma’s Revenge Android , similar to Bonsai Blast, is one of the most fascinating puzzle game fr…
-
Al Shalat v1.7 (Iphone-Ipod-Ipad)Al Shalat v1.7 (Iphone-Ipod-Ipad) All you need for Shalat (Prayer) in the palm of your hand, and ev…
Post a Comment
Post a Comment