Android Tech

The more we share, the more we get

Category Archives: Android basic

TabView (Part 8) – Set background of tabwidget with shape drawable


You can use the example in previous post.

Android define some Drawable Resources which use use to build your own style for application. Here I want to illustrate for Shape Drawable. This is a generic shape defined in XML.

Here is the syntax of it:

We will use this structure in example below.

1. Create a drawable resource for this example like this

<?xml version=”1.0″ encoding=”UTF-8″?>
<shape xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:shape=”rectangle” >
<gradient android:startColor=”#505050″
android:centerColor=”#101010″
android:endColor=”#101010″
android:angle=”270″/>
</shape>

2. Set this drawable resource as background for TabWidget

android:background=”@drawable/tabwidgetbk”

And the final result will like this:

You can download the source code from here

If you modify the attribute “android:angle” to 0, the result will like this:

You can download the source code from here