How to change the font color of selected rows in listview

Source: Internet
Author: User

Purpose: select an item and set its font to # 3197FF. If it is not selected, the font of the item is # FFFFFF.

Use selector like setting the selected row item background image in listvew. However, the color settings here should be set in textview in listview.Copy codeThe Code is as follows: <SPAN style = "COLOR: #666666"> <? Xml version = "1.0" encoding = "UTF-8"?>
<TableLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
>
<TableRow>
<TextView
Android: id = "@ + id/name_ TV"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: textSize = "25px"
Android: textColor = "@ drawable/itemcolor">
</TextView>
</TableRow>
</TableLayout> </SPAN>

Similarly, define the itemcolor. xml file to modify the font color of the selected row:Copy codeThe Code is as follows: <SPAN style = "COLOR: #666666"> <? Xml version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: android = "http://schemas.android.com/apk/res/android">
<! -- Font color without focus -->
<Item
Android: state_selected = "false"
Android: color = "# FFFFFF"/>
<! -- Font color when selected -->
<Item
Android: state_selected = "true"
Android: color = "# 3197FF"/>
<! -- Font color when the focus is obtained in non-touch mode and clicked -->
<Item
Android: state_focused = "true"
Android: state_pressed = "true"
Android: color = "# 3197FF"/>
</Selector> </SPAN>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.