[Android]_ch7.6_存取res目錄內的資源
存取res目錄內的資源基本上都必須透過該資源的resource
ID,說明如下:
ID,說明如下:
存取文字檔:透過「R.string 」
存取圖形檔:透過「R.drawable」
存取多媒體檔:透過「R.raw」
存取layout檔:透過「R.layout」
Resources resources=getResources();
CharSequence s1=resources.getText(R.string.s2);
String s2=resources.getString(R.string.s2);
tv4.setText(s1);
tv5.setText(s2);
Drawable drawable=resources.getDrawable(R.drawable.a11);
iv.setImageDrawable(drawable);
MediaPlayer mediaPlayer=MediaPlayer.create(MainActivity.this, R.raw.lee);
mediaPlayer.start();
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="s1">杜仲教學,Adorid手機程式,2019年</string>
<string name="s2"><B>杜仲教學</B>,<i>Adorid手機程式</i>,<U>2019年</U></string>
</resources>
沒有留言:
張貼留言