'resource'에 해당되는 글 1건

  1. 2014.09.29 앱 실행중에 Resources String.xml 내용 갱신
Android 안드로이드2014. 9. 29. 16:11









앱 실행중 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






Posted by 코드버무려