我正在制作一个Madlibs应用程序。我需要加粗用户在输出故事中输入的信息。但是,我不太确定如何在textview中只加粗那些特定的字符串。值得注意的是,我的应用程序用每个字符串替换故事中的所有“wx”。这就是故事的创造方式。如果有人可以帮助我用粗体字符串而不是常规字符串替换故事中的所有“wx”,我们将不胜感激。谢谢。
public void gather() {
ViewGroup layout = (ViewGroup) view.findViewById(R.id.anskey_clover);
View[] views = new View[layout.getChildCount()];
int[] ids = new int[layout.getChildCount()];
for (int i = 0; i < layout.getChildCount(); i++) {
ids[i] = layout.getChildAt(i).getId();
}
for (int i = 0; i < layout.getChildCount(); i++) {
BootstrapEditText au = (BootstrapEditText) view.findViewById(ids[i]);
stringbuffer.append(au.getText().toString() + "\n");
}
//setContentView(outLayout);
//TextView outview = (TextView) view.findViewById(outviewid);
//outview.setText(stringbuffer.toString());
}
public void postIt() {
String str = "let's go to the park";
String str2;
String newstr = null;
//setContentView(outLayout);
TextView outview = (TextView) view.findViewById(outviewid);
str = (String) outview.getText();
stringviews = stringbuffer.toString().split("\n"); // turns the
// stringbuffer from
// getAllXml() into
// an array and
// assigns to
// stringviews.
for (int i = 0; i < stringviews.length; i++) {
str2 = stringviews[i];
newstr = str.replaceFirst("wx", str2); // replaces all the "wx"s in
// the
// main_class_activity_out
// textview with values from
// strinvgviews.
str = newstr;
}
outview.setText(newstr);
ScrollView textScroll = (ScrollView) view.findViewById(R.id.scrollView1);
//textScroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
textScroll.getLayoutParams().width = LayoutParams.FILL_PARENT;
textScroll.getLayoutParams().height = LayoutParams.FILL_PARENT;
//textScroll.setPadding(0, 0, 0, 250);
stringbuffer.delete(0, stringbuffer.length());
}