在选项卡式片段中更改列表视图的文本颜色
Change Text color for Listview in Tabbed Fragment
我用 viewpager 创建了一个选项卡式片段。 farg1 中有简单的列表视图来显示数据。但是文字的颜色是白色的。怎么改成黑色。 listview没有给Textcolor属性设置。
以下是应用于片段的片段主题的代码:
<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>
下面是布局代码 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>
在适配器中使用相同的 xml 而不是使用 android.R.layout.simple_list_item_1
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);
我用 viewpager 创建了一个选项卡式片段。 farg1 中有简单的列表视图来显示数据。但是文字的颜色是白色的。怎么改成黑色。 listview没有给Textcolor属性设置。 以下是应用于片段的片段主题的代码:
<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>
下面是布局代码 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>
在适配器中使用相同的 xml 而不是使用 android.R.layout.simple_list_item_1
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);