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>
Download the files.
Related:
- Create custom Button using StateListDrawable
-- Delivered by Feed43 service
Related Posts
There is no other posts in this category.Popular
-
Winamp v0.9.2 For AndroidWinamp v0.9.2 For Android Requirements: Android 2.1 Overview: If you already have the official app …
-
DocScanner for Symbian MobilesDocScanner for Symbian Mobiles DocScanner is a perfect business application to have on your Symbia…
-
PicoBrothers YouTube Downloader v2.2.2 BetaPicoBrothers YouTube Downloader v2.2.2 Beta Support/Info: S60v5/S^3 Signed Details: YouTube Downloa…
-
Death Worm v1.09 Iphone-Ipad-Ipod TouchDeath Worm v1.09 Iphone-Ipad-Ipod Touch Over 3,000,000 of downloads for Death Worm, 3 Million peopl…
-
[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…
-
Game HD Modern Combat Sandstorm HVGA for Android PhoneGame HD Modern Combat Sandstorm HVGA for Android Phone Modern Combat Sandstorm HD is a war game th…
-
[Gameloft] Ice Age 4: Continental Drift S40v6, S60v3, v5, Samsung, LG, Sony EricsionIce Age 4: Continental Drift is the latest game just released by Gameloft in this June 2012. The g…
Post a Comment
Post a Comment