简体   繁体   English

更改选项卡式片段中列表视图的文本颜色

[英]Change Text color for Listview in Tabbed Fragment

i created a tabbed fragment with viewpager.我用 viewpager 创建了一个标签片段。 There is simple listview to show data in farg1.有一个简单的列表视图来显示 farg1 中的数据。 But color of text is coming as white.但是文本的颜色变成了白色。 How to change it to black.怎么改成黑色。 listview does not give Textcolor property to set. listview 没有给 Textcolor 属性设置。 below is code used for fragtheme applied to fragment:下面是用于片段的片段主题的代码:

<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>

Below is code for layout xml:下面是布局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>

presently set background as black to make it readable.目前将背景设置为黑色以使其可读。

you can create list_textview.xml and define color in that.您可以创建 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>

use the same xml in adapter instead of using android.R.layout.simple_list_item_1在适配器中使用相同的 xml 而不是使用android.R.layout.simple_list_item_1

arrayAdapter = new ArrayAdapter(getActivity(),R.layout.list_textview, R.id.list_content,recentlistarray); 
recentlist.setAdapter(arrayAdapter);

OR或者

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM