【发布时间】:2018-04-15 08:35:29
【问题描述】:
在我的应用程序中, 应该允许用户更改对齐、颜色、大小和其他文本属性,但它实现了对所有文本内容的对齐更改,当我触摸开箱时,大小和颜色将返回到第一个视图
所以我想知道如何解决这个问题。
【问题讨论】:
标签: java android android-layout android-edittext
在我的应用程序中, 应该允许用户更改对齐、颜色、大小和其他文本属性,但它实现了对所有文本内容的对齐更改,当我触摸开箱时,大小和颜色将返回到第一个视图
所以我想知道如何解决这个问题。
【问题讨论】:
标签: java android android-layout android-edittext
你必须使用 spandable 。
为您的文本颜色使用 ForegroundColorSpan :
SpannableStringBuilder ssb = new SpannableStringBuilder("Hello Everyone");
ForegroundColorSpan colorSpan = new ForegroundColorSpan(
context.getResources()
// Specify your color
.getColor(R.color.your_font_color));
realPrice.setSpan(colorSpan,
0, // Start index of the single word
4, // End index of the single word
Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
yourEditText.setText(ssb);
对于您的文本大小,请这样做:
String s= "Hello Everyone";
SpannableString ss1= new SpannableString(s);
ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size
ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);// set color
TextView tv= (TextView) findViewById(R.id.textview);
tv.setText(ss1);
输入你的字符串而不是“大家好”
【讨论】: