在android中设置android Listview的样式 我正在尝试在android中设计我的列表视图

在android中设置android Listview的样式 我正在尝试在android中设计我的列表视图,android,android-listview,Android,Android Listview,我想做的事情:我想获得列表视图的背景色和文本色,如下图所示 [编辑] 我还希望在选择行时具有自定义的单击效果 我目前拥有的内容:使用基本适配器开发的简单列表视图 我的当前listview快照: main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height=

我想做的事情:我想获得
列表视图的背景色和文本色,如下图所示

[编辑] 我还希望在选择行时具有自定义的单击效果

我目前拥有的内容:使用基本适配器开发的简单列表视图

我的当前listview快照


main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
     />
</LinearLayout>
<resources>



    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

ImageTextListBaseAdapterActivity.java

public class ImageTextListBaseAdapterActivity extends Activity {

    public static final String[] titles = new String[] { "Strawberry",
        "Banana", "Orange", "Mixed" };

    public static final String[] descriptions = new String[] {
        "It is an aggregate accessory fruit",
        "It is the largest herbaceous flowering plant", "Citrus Fruit",
    "Mixed Fruits" };

    public static final Integer[] images = { R.drawable.one,
        R.drawable.two, R.drawable.three, R.drawable.four };

    ListView listView;
    List<RowItem> rowItems;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        rowItems = new ArrayList<RowItem>();
        for (int i = 0; i < titles.length; i++) {
            RowItem item = new RowItem(images[i], titles[i], descriptions[i]);
            rowItems.add(item);
        }

        listView = (ListView) findViewById(R.id.list);
        CustomBaseAdapter adapter = new CustomBaseAdapter(this, rowItems);
        listView.setAdapter(adapter);
    }

}
公共类ImageTextListBaseAdapterActivity扩展活动{
公共静态最终字符串[]标题=新字符串[]{“草莓”,
“香蕉”、“橘子”、“混合”};
公共静态最终字符串[]说明=新字符串[]{
“它是一种聚合的附属水果”,
“最大的草本开花植物”、“柑橘类水果”,
“混合水果”};
公共静态最终整数[]图像={R.drawable.one,
R.drawable.two,R.drawable.three,R.drawable.four};
列表视图列表视图;
列出项目;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
rowItems=新的ArrayList();
对于(int i=0;i
Styles.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
     />
</LinearLayout>
<resources>



    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>



如何实现我的目标,获得我的列表视图,如第一个快照所示,以获得您提到的背景:

您的列表行xml应该如下所示:

<RelativeLayout
android:id="@+id/relId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray">
    <TextView 
         android:id="@+id/txt"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:textColor="@color/blue_color_here"/>
</RelativeLayout>

注意:在这里,在颜色文件(color.xml资源文件)中定义蓝色

另外,在自定义适配器中传递此布局,并使用此布局将项目填充到列表中

对于单击效果,创建一个可绘制的,并将listSelector的背景设置为可绘制,同时将相对布局的背景设置为可绘制

可拉丝的外观可能如下所示:

<item android:state_pressed="true" android:drawable="@drawable/when_pressed"/>
<item android:drawable="@android:color/darker_gray"/>


在listview中为背景设置背景,为文本设置textColor。@Manmohan。。。。请参阅编辑。。。。我还尝试在列表选择上获得点击效果。你可以设置一个xml作为背景,我们也可以使用按钮作为点击/聚焦时的差异效果/default@Manmohan .... 请你给我看一个样品作为你的答案好吗?这是一个很好的。。。只是一个快速与谷歌!谢谢你[+1]。。。。有关信息。。。。您还可以使用自定义选择器编辑答案,用于列表行选择。。。。我在第二个问题中提到过