在android中更改列表视图的文本颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2354176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing text color of list view in android
提问by BIBEKRBARAL
is it possible to change list view's text color in android?
是否可以在android中更改列表视图的文本颜色?
回答by ranjit patel
Yes possible
是的可能
please add a separate layout with the textview
请使用文本视图添加单独的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="6dip"
android:textColor="@color/black"
android:paddingRight="10dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
and change the **android.R.layout.simple_list_item_1**to and pass the textview id like this
并将**android.R.layout.simple_list_item_1**更改 为并像这样传递 textview id
new ArrayAdapter(this, R.layout.layoutfilename,*android.R.id.text1*,userList);
new ArrayAdapter(this, R.layout.layoutfilename,* android.R.id.text1*,userList);
回答by Tristan Warner-Smith
You can use themes to set the styles for your TextViews
.
From the Android dev site.
您可以使用主题为您的TextViews
. 来自Android 开发网站。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
Then to use it:
然后使用它:
<TextView style="@style/CodeFont" />
Edit - based on comment
编辑 - 基于评论
You asked about multiple color in the same TextView: Your best bet is to use html. Which you set in a TextView for example:
您在同一个 TextView 中询问了多种颜色:您最好的选择是使用 html。例如,您在 TextView 中设置的内容:
myTextView.setText(Html.fromHtml("<p style="color:red">" + someText + "</p><p style="color:blue">" + someOtherText + "</p>"));
myTextView.setText(Html.fromHtml("<p style="color:red">" + someText + "</p><p style="color:blue">" + someOtherText + "</p>"));
回答by Ta Sas
Have you tried something like android:textColor="#ffffff"
in your layout.xml file?
你有没有android:textColor="#ffffff"
在你的 layout.xml 文件中尝试过类似的东西?