将数组中的特定字符串设置为粗体

时间:2012-06-06 14:16:15

标签: android string

我将用户的短信收件箱显示为列表视图。我想加粗from和message字符串,但由于它们是数组的一部分,所以我无法弄清楚如何。我已经尝试在strings.xml中使用 标签,但这不起作用。如何将这两个字符串设置为粗体?

        public ArrayList fetchInbox() {  
        ArrayList sms = new ArrayList();  
        Uri uriSms = Uri.parse("content://sms/inbox");  
        Cursor cursor = getContentResolver().query(uriSms, new String[]{"_id", "address", "date", "body"},null,null,null);   
        cursor.moveToFirst();  
        while  (cursor.moveToNext())  
        {  
               String address = cursor.getString(1);  
               String body = cursor.getString(3);
               sms.add(from + " " + address + "\n" + message + " " + body);
        }  
        return sms;  
    }

    private void setStrings() {
        from = (String) getResources().getString(R.string.from);
        message = (String) getResources().getString(R.string.message);
        }

1 个答案:

答案 0 :(得分:0)

您可以使用Html.fromHtml( String )

TextView txt = (TextView)findViewById(R.id.txt);
txt.setText( Html.fromHtml( "<b>"+from+"</b> " + message ) );