0

我将用户的短信收件箱显示为列表视图。我想将 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);
        }
4

1 回答 1

0

你可以Html.fromHtml( String )这样使用:

TextView txt = (TextView)findViewById(R.id.txt);
txt.setText( Html.fromHtml( "<b>"+from+"</b> " + message ) );
于 2012-06-06T14:32:17.027 回答