使用android.R.layout.simple_list_item_1与光的主题 [英] Use android.R.layout.simple_list_item_1 with a light theme

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

问题描述

据我了解,使用 Android的时候:项的ListView ,它使用了 android.R.layout.simple_list_item_1 作为列表项的布局和 android.R.id.text1 作为内部的TextView中的ID布局。请纠正我,如果我错了。

知道了这一点,我想创造我自己的适配器,但使用相同的布局资源,以提供与平台用户界面的一致性。因此,我试过如下:

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

不幸的是,因为我用的是光的主题(我有安卓主题=@安卓风格/ Theme.Light在我的 <应用> ),列表项出现白色的文字,使它们无法读取

然而,使用 Android的时候:项来指定项目的静态列表,项正确显示,有黑色文本颜色

我是什么做错了吗?我怎样才能让我的动态适配器使用标准的布局,但工作与光的主题?

解决方案
  

请,纠正我,如果我错了。

您至少八九不离十错误。它使用 com.android.internal.R.layout.simple_list_item_1 。虽然这是几乎相同的 android.R.layout.simple_list_item_1 ,可以为主题的不同。

另外,不要使用 getApplicationContext()。只需使用你的活动上下文。看看是否有帮助。

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.

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 }
);

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.

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.

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.

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天全站免登陆