Android TextColor与ListView背景相同该怎么办?

Android TextColor与ListView背景相同该怎么办?,android,listview,Android,Listview,我的应用程序中有一个使用HoloLight主题的非常简单的ListActivity。正在填充我的ListView,但文本仅在项目高亮显示时可见。我如何解决这个问题?为什么会发生 编辑:澄清。我希望找到一个全局解决方案,而不是在每个列表视图中本地解决这个问题。您可以尝试制作自己的适配器,然后使用它在列表视图中显示项目 你可以在这里找到更多的信息:但我知道互联网上还有很多其他网站可以提供很好的解释(谷歌是你的朋友)更新: 下面是一个示例自定义适配器,它加载一个自定义布局,只要在所有列表中使用该布局,

我的应用程序中有一个使用HoloLight主题的非常简单的ListActivity。正在填充我的ListView,但文本仅在项目高亮显示时可见。我如何解决这个问题?为什么会发生


编辑:澄清。我希望找到一个全局解决方案,而不是在每个列表视图中本地解决这个问题。

您可以尝试制作自己的适配器,然后使用它在列表视图中显示项目


你可以在这里找到更多的信息:但我知道互联网上还有很多其他网站可以提供很好的解释(谷歌是你的朋友)

更新:

下面是一个示例自定义适配器,它加载一个自定义布局,只要在所有列表中使用该布局,它们的行为方式和外观都将相同,要使其工作,您只需定义要显示的内容和使用的对象类型

自定义适配器:

public class YourAdapter extends ArrayAdapter<String> {
    private final Context context;
    private List<Object> YourObjects;

    public YourAdapter(Context context, List<Object> YourObjects, List<String> headings) {
        super(context, R.layout.list_view_stories, headings);
        this.context = context;
        this.YourObjects = null != YourObjects ? YourObjects : new ArrayList<Object>();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        /*Setup the things need it to inflate each row*/
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_view_stories, parent, false);

        /*Retrieves the views for the heading and title from the layout*/
        TextView heading = (TextView) rowView.findViewById(R.id.title);
        TextView summary = (TextView) rowView.findViewById(R.id.summary);

        heading.setText(YourObjects.get(position).getHeading());
        summary.setText(YourObjects.get(position).getSummary());

        /*Returns the row with the content placed*/
        return rowView;

    }

} 
然后在values文件夹中创建一个资源,下面是我使用的一些颜色的示例

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <color name="black">#000000</color>
    <color name="white">#ffffff</color>
    <color name="gray">#909090</color>
    <color name="ligth_blue">#2E9AFE</color>

</resources>

#000000
#ffffff
#909090
#2E9AFE

使用自定义列表视图。您可以用自己的方式自定义每一行。有很多listview的例子只是用谷歌搜索一下。也可以看看这个链接

有几个很好的答案。但是,其中大多数都包括编写一个新的适配器,这是不必要的工作。最重要的是,您应该在xml中设置所需的颜色。我用simple_list_item_2的源代码编写了一个新布局,并添加了一行来更改文本颜色。经过测试,效果良好

<?xml version="1.0" encoding="utf-8"?>
<!--
/*
 * Copyright (C) 2006-2007 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-->

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:mode="twoLine"
    android:paddingBottom="2dip"
    android:paddingTop="2dip" >

    <TextView
        android:id="@android:id/text1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dip"
        android:layout_marginTop="6dip"
        android:textColor="?android:attr/textColorPrimaryInverseDisableOnly"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@android:id/text2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@android:id/text1"
        android:layout_below="@android:id/text1"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</TwoLineListItem>


我不认为这是一个解决方案,因为每次创建列表视图时都会出现此问题。我想找个地方应用更改,以便我的列表视图始终保持相同的颜色。无论如何谢谢你!在这种情况下,这确实不是最好的选择。当然,您总是使用相同的适配器。因此,这仍然是一个可能的解决方案,但可能不是最好的。主题不应该处理这个问题吗?谢谢。我不明白为什么我应该写一个自定义列表视图来应用不同的文本颜色。在这种情况下,我只需编写一个新的项目布局。
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <color name="black">#000000</color>
    <color name="white">#ffffff</color>
    <color name="gray">#909090</color>
    <color name="ligth_blue">#2E9AFE</color>

</resources>
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
 * Copyright (C) 2006-2007 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-->

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:mode="twoLine"
    android:paddingBottom="2dip"
    android:paddingTop="2dip" >

    <TextView
        android:id="@android:id/text1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dip"
        android:layout_marginTop="6dip"
        android:textColor="?android:attr/textColorPrimaryInverseDisableOnly"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@android:id/text2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@android:id/text1"
        android:layout_below="@android:id/text1"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</TwoLineListItem>