color

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 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 Text Color

In Android, we can set text color for textview, edittext, buttons, etc...

Example:-

Input

Output

Syndicate content