如何在运行时设置Xamarin Android ForegroundColorsPan.ForegroundColor属性?
Xamarin Android ForegroundColorspan.ForegroundColor属性已阅读。
如果要动态更改跨度的颜色,我们如何在运行时设置此?
更新
为了提供更多信息,我正在尝试重新创建Android文档中给出的示例。以下代码在Java中,但是由于Xamarin Android中跨度颜色属性的读取性质,该代码如何在Xamarin中重新创建?
https://develoveler.android.com/guide.com/guide/topics/topics/text/spans
public class MainActivity extends AppCompatActivity {
private BulletPointSpan bulletSpan = new BulletPointSpan(Color.RED);
@Override
protected void onCreate(Bundle savedInstanceState) {
...
SpannableString spannable = new SpannableString("Text is spantastic");
// setting the span to the bulletSpan field
spannable.setSpan(bulletSpan, 0, 4, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
styledText.setText(spannable);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// change the color of our mutable span
bulletSpan.setColor(Color.GRAY);
// color won’t be changed until invalidate is called
styledText.invalidate();
}
});
}
}
The Xamarin Android ForegroundColorSpan.ForegroundColor Property is readonly.
How can we then set this at runtime if we want to dynamically change the color of a span?
UPDATED
To provide more information, I'm trying to recreate the example given in Android documentation. The below code is in Java, but due to the read only nature of the span's color property in Xamarin Android, how can this code be recreated in Xamarin?
https://developer.android.com/guide/topics/text/spans
public class MainActivity extends AppCompatActivity {
private BulletPointSpan bulletSpan = new BulletPointSpan(Color.RED);
@Override
protected void onCreate(Bundle savedInstanceState) {
...
SpannableString spannable = new SpannableString("Text is spantastic");
// setting the span to the bulletSpan field
spannable.setSpan(bulletSpan, 0, 4, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
styledText.setText(spannable);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// change the color of our mutable span
bulletSpan.setColor(Color.GRAY);
// color won’t be changed until invalidate is called
styledText.invalidate();
}
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论