首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义ListItem颜色android_simple_listitem

自定义ListItem颜色android_simple_listitem
EN

Stack Overflow用户
提问于 2013-12-22 05:19:24
回答 2查看 77关注 0票数 0

为了定制android simple list item 1的颜色,我做了一个styles.xml,它看起来像

代码语言:javascript
复制
<resources>
    <style name="BlackText">
        <item name="android:textColor">#000000</item>
    </style>
</resources>

并将其应用于清单文件中的活动,如下所示

代码语言:javascript
复制
 android:theme="@style/BlackText"

这在某种程度上解决了我的问题,默认列表项的颜色被更改为黑色,但我在该活动上的对话框的文本颜色也被更改为黑色,这是我不想要的。另一种选择是创建我自己的adapter并覆盖bindView方法,我不想这样做。还有其他选择吗?

编辑

我做了我自己的布局,比如

代码语言:javascript
复制
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/somerandomid"

    android:padding="5sp"
    android:layout_width="fill_parent"
    android:textSize="15sp"
    android:singleLine="true"
    android:background="#FFF"
    android:textColor="#000"
    android:gravity="center"
    android:layout_height="fill_parent"/>

并像这样使用它

代码语言:javascript
复制
 adapter= new SimpleCursorAdapter(SomeActivity.this,R.layout.myownlayout, cursor, columns, views);

致以问候。

EN

回答 2

Stack Overflow用户

发布于 2013-12-22 05:30:09

因此,您可以使用一个TextView创建自己的布局,而不是将ListView绑定到android.R.layout.simple_list_item_1。假设布局将被命名为listviewlayout.xml。它看起来像这样:

代码语言:javascript
复制
<?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" >

    <TextView
        android:id="@+id/textviewlist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:text="TextView" >
    </TextView>

</LinearLayout>

您可能需要移动TextView以将其放在正确的位置。然后,从清单中删除此部件:

代码语言:javascript
复制
android:theme="@style/BlackText"

然后像这样设置ListView适配器:

代码语言:javascript
复制
setListAdapter(new ArrayAdapter(this, R.layout.listviewlayout, listItems));
票数 1
EN

Stack Overflow用户

发布于 2013-12-22 07:05:36

显然,我必须复制默认布局中指定的id,所以我更改了

代码语言:javascript
复制
android:id="@+id/somerandomid"

代码语言:javascript
复制
android:id="@android:id/text1" 

对我来说一切都很顺利

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20723667

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档