0

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

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

4

4 回答 4

1

有几个很好的答案。但是,其中大多数包括编写一个新的适配器,这是不必要的工作。最重要的是您应该在 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>
于 2012-12-26T16:01:19.963 回答
0

您可以尝试制作自己的适配器,然后可以使用它来显示 ListView 中的项目

您可以在此处找到更多信息:http ://www.vogella.com/articles/AndroidListView/article.html但我知道互联网上还有许多其他网站可以提供很好的解释(Google 是您的朋友)

于 2012-12-22T13:25:01.800 回答
0

更新:

这是一个加载自定义布局的示例自定义适配器,只要您在所有列表中使用这个,它们的行为方式和外观都会相同,并且要使其工作,您只需要定义您想要的显示以及您使用的是什么类型的对象。

自定义适配器:

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;

    }

} 

自定义布局:

<?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"
    android:padding="20dip"
    android:background="@color/ligth_blue" >

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/heading"
        android:textColor="@color/black"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/summary"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/summary"
        android:textColor="@color/white"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</LinearLayout>

更改布局属性中的颜色。

android:textColor="@color/black"

然后在值文件夹中创建一个资源,这是我使用的一些颜色的示例。

<?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>
于 2012-12-22T13:26:24.800 回答
0

使用自定义 ListView。您以自己的方式自定义每一行。有很多 listview 的例子只是谷歌它。http://www.ezzylearning.com/tutorial.aspx?tid=1763429。也看看这个链接。http://codehenge.net/blog/2011/05/customizing-android-listview-item-layout/

于 2012-12-22T13:28:10.993 回答