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
-
Twitter v3.1.1 for AndroidTwitter v3.1.1 for Android Official Twitter app for Android. Follow your interests: instant updates…
-
Jelly Bean Keyboard PRO v1.4.4Jelly Bean Keyboard PRO v1.4.4 APK Google play Store Go To Adf.ly PRO Only featur…
-
Tap Sonic 1.0.9!Stop using this version! New and updated version click here APK (1.09) Data_1 Data_2 Data_3 3 So…
-
iWindows v1.51 S60v5iWindows v1.51 S60v5 Support/Info : Symbian^1^3 Anna Belle UnSigned Retail by DSPDA™ Details : iWin…
-
Espier Launcher for Android PhoneEspier Launcher for Android Phone You're feeling bored with the theme and launcher your Android…
-
Android Apps with EclipseEclipse is the most adopted integrated development environment (IDE) for Java programmers. And, now…
-
FriendCaster Pro for Facebook v4.2.0.1FriendCaster Pro for Facebook v4.2.0.1 Requirements: Android 1.6+ Overview: The best Facebook exper…
Post a Comment
Post a Comment