如何使用資源文件?-Assets、Drawable、Strings、Colors等

如何使用資源文件?-Assets、Drawable、Strings、Colors等

參考來源:突破關鍵Android核心技術102問

圖片文件:(res/drawable(通用)、res/drawable-hdpi(高解析)、res/drawable-mdpi(中解析)、res/drawable-ldpi(低解析))
音樂、html文件:(Assets)
UI-Layout文件:(res/layout)
定義選單:(res/menu)
定義文字:(res/values/string.xml,其中values依語系命名,例如:台灣中文(res/values-zh-rTW/string.xml))
定義陣列(文字/數值):(res/values/arrays.xml)
定義顏色:(res/values/colors.xml)
定義樣式:(res/values/styles.xml)
定義尺寸:(res/values/dimens.xml)
preferences(偏好設定):(res/xml)
/*資源引用*/
//文字
getResource().getString(R.string.app_name_version);
//若app_name_version在strings.xml定義為: My First App Ver. %s
//格式化文字
getResource()getString.(R.string.app_name_version, new String[]{"1.0"});//輸出結果 MyFirst App Ver. 1.0
//文字陣列
String[] contents = getResource().getStringArray(R.array.arrays_content);

相關取資源的方法

2012-11-21_20-58-47