---
title: "获取string.xml中的可变字符串"
author: "yutinglong"
date: "2011-01-14T15:47:11Z"
tags: []
categories: ["移动开发"]
slug: "string-xml"
draft: false
lastmod: "2011-01-14T15:47:11Z"
id: 871461
url: "https://yutinglong.iteye.com/blog/871461"
---

1、在string.xml中添加一个字符串，其中含有可变字符%s，代码如下。

```
<string name="login_about_title">Beem %s - About</string>
```

2、在代码中使用下列代码获取该字符串。

```
String title = getString(R.string.login_about_title, "字符串");
```

 其中“字符串”将会替换string.xml中的%s。

3、得到的字符串并打印，效果如下。 

```
title = "Beem 字符串 - About"; 
```