Android 如何在iText中加粗文本的一部分

Android 如何在iText中加粗文本的一部分,android,itext,Android,Itext,我需要在我的应用程序中获取部分粗体文本。所以基本上我想要实现的是这样的:地址:123街。现在我在哪里用粗体显示:地址:123街 以下是我正在使用的代码: PdfPTable table2 = new PdfPTable(3); table2.setWidthPercentage(100); table2.addCell(getCell("Address: " + SaveString, PdfPCell.ALIGN_LEFT));

我需要在我的应用程序中获取部分粗体文本。所以基本上我想要实现的是这样的:地址:123街。现在我在哪里用粗体显示:地址:123街

以下是我正在使用的代码:

PdfPTable table2 = new PdfPTable(3);
            table2.setWidthPercentage(100);
            table2.addCell(getCell("Address:  " + SaveString, PdfPCell.ALIGN_LEFT));
            table2.addCell(getCell("Name:  " + SaveStringA, PdfPCell.ALIGN_CENTER));
            table2.addCell(getCell("Last Name:  " + SaveStringB, PdfPCell.ALIGN_RIGHT));
            table2.setSpacingAfter(15);
            doc.add(table2);  

public PdfPCell getCell(String text, int alignment) {
    PdfPCell cell = new PdfPCell(new Phrase(text));
    Font bold = FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD);
    Paragraph p1 = new Paragraph(text, bold);
    cell.setPadding(0);
    cell.addElement(p1);
    cell.setHorizontalAlignment(alignment);
    cell.setBorder(PdfPCell.NO_BORDER);

    return cell;
希望有人能帮忙


谢谢

您可以尝试使用Chunk,如下所示:

SpannableStringBuilder str = new SpannableStringBuilder("Address: 123 Street");
str.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), 0, "Address:".length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
yourTextView.setText(str);
Font bold = FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD);
Chunk chunkAddress= new Chunk("Address:  ", bold);
Chunk ChunkAddressDetails = new Chunk("123 Street.");

Phrase phrase = new Phrase();
phrase.add(chunkAddress);
phrase.add(ChunkAddressDetails);

Paragraph paragraph= = new Paragraph();
paragraph.add(phrase);

再见,你好,谢谢。但我试过了,但没有成功:-(谢谢,但测试时它似乎不起作用:-(这看起来很合理)。