使用带有浅色主题的 android.R.layout.simple_list_item_1 [英] Use android.R.layout.simple_list_item_1 with a light theme

查看:18
本文介绍了使用带有浅色主题的 android.R.layout.simple_list_item_1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到当将 android:entriesListView 一起使用时,它使用 android.R.layout.simple_list_item_1 作为布局一个列表项和 android.R.id.text1 作为该布局内 TextView 的 ID.如果我错了,请纠正我.

I have learned that when using android:entries with a ListView, it uses android.R.layout.simple_list_item_1 as the layout for a list item and android.R.id.text1 as the ID of the TextView inside that layout. Please, correct me if I'm wrong.

知道这一点后,我想创建自己的适配器,但使用相同的布局资源,以提供与平台的 UI 一致性.因此,我尝试了以下操作:

Knowing this, I wanted to create my own adapter but use the same layout resources, in order to provide UI consistency with the platform. Thus, I tried the following:

mAdapter = new SimpleCursorAdapter(
    getApplicationContext(),
    android.R.layout.simple_list_item_1,
    mSites,
    new String[] { SitesDatabase.KEY_SITE },
    new int[] { android.R.id.text1 }
);

不幸的是,因为我使用的是浅色主题(我的 中有 android:theme="@android:style/Theme.Light"),列表项显示为白色文本,使其不可读.

Unfortunately, because I am using a light theme (I have android:theme="@android:style/Theme.Light" in my <application>), the list items appear with white text, making them unreadable.

但是,当使用 android:entries 指定静态项目列表时,项目显示正确,文本颜色为黑色.

However, when using android:entries to specify a static list of items, the items appear correctly, with black text color.

我做错了什么?如何让我的动态适配器使用标准布局但使用浅色主题?

What am I doing wrong? How can I make my dynamic adapter use the standard layout but work with a light theme?

推荐答案

如果我错了,请纠正我.

Please, correct me if I'm wrong.

你至少错了.它使用 com.android.internal.R.layout.simple_list_item_1.虽然这与 android.R.layout.simple_list_item_1 几乎相同,但它的主题可能不同.

You are at least sorta wrong. It uses com.android.internal.R.layout.simple_list_item_1. While that is nearly identical to android.R.layout.simple_list_item_1, it may be themed differently.

另外,永远不要使用getApplicationContext().只需使用您的 Activity 作为 Context.看看这是否有帮助.

Also, never use getApplicationContext(). Just use your Activity as the Context. See if that helps.

这篇关于使用带有浅色主题的 android.R.layout.simple_list_item_1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆