【问题标题】:in StringBuffer i want to add half bold text and half normal in append在 StringBuffer 中,我想在追加中添加半粗体文本和半正常文本
【发布时间】:2015-02-03 12:40:43
【问题描述】:

我如何通过 html.fromhtml 设置半粗体文本我尝试但在 BufferString 的追加中不起作用追加它的工作正常请帮助我这里是代码

String amt = "AMOUNT: ";
                Spanned tyyy =Html.fromHtml("<b>"+"TYPE: "+"</b>");
                String Dat = "DATE: ";
                String des = "DESCRIPTION: ";

                buffer.append(Html.fromHtml("<b>"+amt+"</b>"+"<small>"+cc.getString(cc.getColumnIndex("AMOUNT"))+"</small>")+"\n");
                buffer.append(tyyy+cc.getString(cc.getColumnIndex("TYPE"))+"\n");

【问题讨论】:

    标签: android html stringbuffer


    【解决方案1】:

    如果不需要来自HTML,可以使用SpannableStringBuilder:

    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append("TYPE:");
    // bold the current text
    int boldStartIndex = 0;
    int boldEndIndex = bulder.length();
    builder.setSpan(new StyleSpan(Typeace.BOLD, boldStartIndex, boldEndIndex, Spanned.FLAG_EXCLUSIVE_EXCLUSIVE));
    // append the rest, it will not be bolded
    builder.append("the-rest-of-your-data");
    

    然后,您可以通过TextView.setText(builder); 将构建器直接设置为 TextView。这可能是比使用 HTML 更好的方法,因为 HTML 标记支持没有很好的文档记录,并且可能不受各种设备的支持。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 2017-01-10
      相关资源
      最近更新 更多