Java 更改选项卡式片段中Listview的文本颜色

Java 更改选项卡式片段中Listview的文本颜色,java,android,listview,fragment,textcolor,Java,Android,Listview,Fragment,Textcolor,我用viewpager创建了一个选项卡式片段。有一个简单的列表视图以farg1格式显示数据。但文本的颜色是白色的。如何将其更改为黑色。listview不提供要设置的Textcolor属性。 下面是应用于片段的fragtheme的代码: <style name="FragTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. -->

我用viewpager创建了一个选项卡式片段。有一个简单的列表视图以farg1格式显示数据。但文本的颜色是白色的。如何将其更改为黑色。listview不提供要设置的Textcolor属性。 下面是应用于片段的fragtheme的代码:

<style name="FragTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:textColor">#000000</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
        <!--   <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>-->
    </style>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的
真的
#000000
@样式/首选项ThemeOverlay.v14.Material
以下是布局xml的代码:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tex1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Recently Used Mobile Number List "
            android:textSize="15sp" />

        <ListView
            android:id="@+id/targetlist" 
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>


目前,将背景设置为黑色以使其可读。

您可以创建list_textview.xml并在其中定义颜色

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center_vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/list_content"
        android:textColor="#000000"
        android:gravity="center"
        android:text="sample"
        android:layout_margin="4dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />
</LinearLayout>


你的意思是要使用自定义的listview。实际上它不是自定义的listview。我们只是在更改添加文本的布局文件。您将没有任何其他直接属性来设置文本的颜色。有一种方法可以让textview在适配器类的listview中使用,并为其设置颜色。arrayAdapter=new arrayAdapter(getActivity().getApplicationContext(),android.R.layout.simple_list_item_1,recentlistarray);设置适配器(arrayAdapter);这就是我设置的方式。我没有得到setListAdapter方法.listview.setadapter(arratAdapter);
arrayAdapter = new ArrayAdapter(getActivity(),R.layout.list_textview, R.id.list_content,recentlistarray); 
recentlist.setAdapter(arrayAdapter);
ArrayAdapter adapter=new ArrayAdapter(
            this, android.R.layout.simple_list_item_1, listItems){

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view =super.getView(position, convertView, parent);

            TextView textView=(TextView) view.findViewById(android.R.id.text1);
            textView.setTextColor(Color.BLACK);

            return view;
        }
    };
    recentlist.setAdapter(arrayAdapter);