background

Android Custom Listview Tutorial - Part 2

Moving ahead from first part Custom List view,  we are going to discuss three things.

1.Adding background colors to Listview

2.Adding different Divider color.

3.Triggering action on listview click.

Step 1:

Listview Background Color

Adding Custom Background color to listview . For an elegance look for an application the listview color play a key role.

[sourcecode language="java"]

convertView.setBackgroundColor((position & 1) == 1 ? Color.WHITE : Color.LTGRAY);

[/sourcecode]

Android Layout Background Image

Now we are going to see about android layout background image. Also you can check our previous post about the android layout background color.

In android, we can set a image to layout as background by using background property in layout.

Android Layout Background Color

In android, we can set the layout background color using background property in layout.
Example for Layout Background Color :-
[sourcecode language="xml"]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#0000ff" />
[/sourcecode]
The output will looks like

Android Button Background Color

Android Button Background Color Example -

We can set the button background color by using the button property 'android:background' .

Android Widgets Button Image

Android Button Background Image Example:-

We can set the Background image for a button by using the button property 'android:background'.

Android Textview Background Color

Here we are going to see an example for setting the Android textview background color...

[sourcecode language="css"]

<TextView android:background="#ff23cf"
android:text="@+id/TextView01"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

[/sourcecode]

By using the android:background="#ff23cf" piece of code the textview background will be filled with #ff23cf color.<

Android- Button Transparent

Here we are going to see how to make a button transparent in Android...

[sourcecode language="css"]

<Button android:background="@android:color/transparent"
android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff" />
[/sourcecode]

By using android:background="@android:color/transparent" the button background will become transparent

Th

Android Textview Tutorial

In this tutorial, we are going to learn about TextView.

In Android if we start any application, we may need to use TextView.

Textview is a View which we can add to any Layout.

How to add TextView in a Layout?

To add a textview to a layout, select the layout you need to add (here I have selected LinearLayout01) & then click the Add Button (shown in green color with plus symbol intimating "Adds a new element")

Syndicate content