【发布时间】:2019-08-10 13:20:23
【问题描述】:
奇怪的请求,我知道,但出于特殊原因,是否可以更改 strings.xml 字符串中文本的颜色?例如,我希望问题文本为特定颜色。当用户单击帮助按钮时,文本出现在 DialogFragment 中。
<string name="vendor_alert_text">Question 1? Answer. Questions 2? Answer. Question 3? Answer</string>
public class CustomerHelpDialog extends AppCompatDialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity());
alertBuilder.setTitle(R.string.help_dialog_title)
.setMessage(R.string.customer_alert_text)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Empty to close the dialog
}
});
return alertBuilder.create();
}}
【问题讨论】:
-
那么这段文字出现在哪里?在
TextView中所有文本都应该是蓝色的,还是在TextView中混合颜色?还是别的地方? -
抱歉,没有说明清楚,当用户单击帮助按钮时,文本会出现在 DialogFragment 中。用代码更新帖子。
-
看看this。
-
真棒你摇滚!有一个很棒的一周朋友。也发现了这个developer.android.com/guide/topics/resources/…。