앱 실행중 Resources 의 String.xml 내용을 바꾸는 코드 [올 펌]
아이템 하나 사용할 때
String.format(String, Object...)
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
Resources res = getResources();
String text = String.format(
res.getString(R.string.welcome_messages),
username, mailCount);
plurals인 경우
<plurals name="welcome_messages">
<item quantity="one">Hello, %1$s! You have a new message.</item>
<item quantity="other">Hello, %1$s! You have %2$d new messages.</item>
</plurals>
Resources res = getResources();
String text = res.getQuantityString(R.string.welcome_messages,
mailCount, username, mailCount);
세번째 방법
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE resources [
<!ENTITY appname "MrQuery">
<!ENTITY author "Oded">
]>
<resources>
<string name="app_name">&appname;</string>
<string name="description">The &appname; app was created by &author;</string>
</resources>
http://stackoverflow.com/questions/3656371/dynamic-string-using-string-xml
'Android 안드로이드' 카테고리의 다른 글
bindService : Main Thread에 서비스를 만들고 Activity와 통신 (0) | 2014.10.14 |
---|---|
AVD에서 구글애드 구글광고가 안뜨고 로딩을 끝낸다고 한다. (0) | 2014.10.13 |
안드로이드 디버그키 경로 변경, AVD 설치 경로 변경 (0) | 2014.09.14 |
이클립스 안드로이드 에물레이터, fragment (0) | 2014.09.07 |
Android Debug Brigde(adb) 유틸 사용 (0) | 2014.09.05 |