我正在尝试更改默认值 TextColor
在 Andoid 上的 Xamarin.Forms ListView 中。
ListView 非常简单:
List<string> cities = new List<string> { "Berlin", "Bonn", "Braunschweig", "Bremen" };
ListView listView = new ListView();
listView.ItemsSource = cities;
Content = listView;
在设备上它看起来像这样:
我想要的是 TextColor
将会是黑色的。
据我了解Xamarin Forms CustomRenderer将会有一个Android.Resource.Layout.SimpleListItem1
为每个项目生成。
SimpleListItem1使用以下文本外观:
android:textAppearance="?android:attr/textAppearanceListItemSmall"
textAppearanceListItemSmall
使用属性textAppearanceMedium
用于渲染,如您所见here .
所以我已将颜色和主题添加到资源中:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<color name="Black">#000000</color>
</resources>
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Holo.Light">
<item name="android:textAppearanceMedium">@style/MyDefaultTextAppearanceM</item>
</style>
<style name="MyDefaultTextAppearanceM" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/Black</item>
</style>
</resources>
我还将主题添加到我的事件的属性中 ( Theme = "@style/MyTheme
)
主题基本上可以工作。与<item name="android:colorActivatedHighlight">@color/Blue4</item>
我可以更改突出显示颜色。
那么如何让ListView中的文本颜色变成黑色呢?我做错了什么?
最佳答案
尝试在设置内容之前添加此内容:
var template = new DataTemplate(typeof(TextCell));
template.SetValue(TextCell.TextColorProperty, Color.Black);
listView.ItemTemplate = template;
关于listview - 更改 Android 上的 Xamarin.Forms Listview 中的默认 TextColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37945497/