zoukankan      html  css  js  c++  java
  • Android ListView(Selector 颜色)

    listview_color.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <ListView
            android:id="@+id/listViewColor"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:choiceMode="singleChoice"
            android:divider="@android:color/darker_gray"
            android:dividerHeight="1dp" >
        </ListView>
    
    </LinearLayout>

    aa.java

    package com.wangzhu.demoselector;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    
    public class ListViewColorActivity extends Activity {
    
        private ListView listViewColor;
    
        private ArrayAdapter<String> colorAdapter;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.listview_color);
            initView();
        }
    
        private void initView() {
            listViewColor = (ListView) findViewById(R.id.listViewColor);
            colorAdapter = new ArrayAdapter<String>(this, R.layout.list_item_color,
                    R.id.item_tv, getResources().getStringArray(
                            R.array.listviewDatas));
            listViewColor.setAdapter(colorAdapter);
        }
    }

    list_item_color.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/list_item_bg_color_selector"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/item_tv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
    </LinearLayout>

    list_item_bg_color_selector.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@color/green" android:state_pressed="true"/>
        <item android:drawable="@color/red" android:state_activated="true"/>
        <item android:drawable="@color/white"/>
    
    </selector>

    strings.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <string-array name="listviewDatas">
            <item>星期一</item>
            <item>星期二</item>
            <item>星期三</item>
            <item>星期四</item>
            <item>星期五</item>
            <item>星期六</item>
            <item>星期日</item>
        </string-array>
    
    </resources>

    color.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <color name="black">#000000</color>
        <color name="red">#ff0000</color>
        <color name="green">#00ff00</color>
        <color name="white">#ffffff</color>
    
    </resources>
  • 相关阅读:
    delphi TMemoryStream读取html文件中文乱码
    tfrxbarcode2dview 和 tfrxbarcode not found 解决办法
    delphi ForceDirectories 用法
    Java Scanner next() 与 nextLine() 区别
    delphi 用superobject解析json
    delphi 方法可以提前声明
    delphi 判断文件是否被占用
    mysql explain用法和结果的含义
    C# SpinWait
    js异步编程
  • 原文地址:https://www.cnblogs.com/xiaoxian1369/p/3691916.html
Copyright © 2011-2022 走看看