Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6934235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:56:01+00:00 2026-05-27T11:56:01+00:00

I have to make another highlight color for ListView item. I use custom adapter

  • 0

I have to make another highlight color for ListView item. I use custom adapter for items, and i have following code:

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:weightSum="1.0"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_weight="0.13"
        android:background="@drawable/booklist_header"
        android:orientation="horizontal"
        android:layout_height="0dp" >

        <ImageView
            android:id="@+id/imageViewBookListBack"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:layout_height="wrap_content"
            android:src="@drawable/back_button" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_weight="0.77"
        android:layout_height="0dp" >

        <ListView
            android:id="@+id/listViewCurrentList"
            android:listSelector="@drawable/selector"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </ListView>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayoutBooklistAdwhirl"
        android:layout_width="fill_parent"
        android:layout_weight="0.1"
        android:layout_height="0dp" >
    </LinearLayout>

</LinearLayout>

Code for item layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageViewBookListItemImage"
        android:layout_width="120dp"
        android:layout_marginTop="15dp"
        android:layout_height="120dp" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="135dp"
        android:layout_marginTop="15dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textViewBookListItemTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textColor="#000000"
            android:textStyle="bold"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textViewBookListItemAuthor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textColor="#000000"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    </LinearLayout>

</LinearLayout>

Code for selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:drawable="@color/green" /> <!-- focused -->
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@color/green" /> <!-- focused and pressed-->
    <item android:state_pressed="true" android:drawable="@color/green" /> <!-- pressed -->
    <item android:drawable="@color/green" /> <!-- default -->
</selector> 

Code for color.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="green">#006400</color>
    <color name="white">#FFFFFF</color>


</resources>

But I have a problem: ListView item doesn’t change color by click! It has white color always. Where have I made mistake?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:56:02+00:00Added an answer on May 27, 2026 at 11:56 am

    This is how you do it:

    First, in your ListView, put the following:

     android:listSelector="#00000000"
    

    This makes your listSelector (the color you normally see when you click the listview) transparent.

    Next, set the LinearLayout of your item layout to this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/selector"
        android:orientation="horizontal" >
    

    I had the same problem a few days ago and it took me ages to figure this out. Hopefully it works for you!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a string 3434.35353 and another string 3593 How do I make
I have to make a decision of which database server to use for my
I have a gridview in an update panel with the following code to select
I created a custom view class because I wanted to have a status item
I have this problem. I need to do the following: get todays date make
I have record from sql database printing into gridview. I want to make another
I have a select list of options. I want to instantly make another select
I have a div that displays a Google map. How do I make another
When a user enters my page, I have to make another AJAX call...to load
I have make a new dropdown navi in css . Chrome, firefox, safari is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.