Android-----Resources
生活随笔
收集整理的這篇文章主要介紹了
Android-----Resources
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? XML文件的讀寫方式基本上是利用DroidDraw,而且也很少有難的地方,復雜布局盡量用Relative,簡單布局用LinearLayout,較為特殊的時候使用FrameLayot,另外兩個AbsoluteLayout和TableLayout很少使用。 ?
記錄一部分用Java實現的功能】
Image //Call getDrawable to get the imageDrawable d = getResources().getDrawable(R.drawable.sample_image);//You can use the drawable then to set the backgroundthis.getTextView().setBackgroundDrawable(d); //or you can set the background directly from the Resource Idthis.getTextView().setBackgroundResource(R.drawable.sample_image); Color Resources res = this.mContext.getResources(); int mainBackGroundColor = res.getColor(R.color.main_back_ground_color); reportString("mainBackGroundColor:" + mainBackGroundColor); ParseXML StringBuffer sb = new StringBuffer();Resources res = activity.getResources();XmlResourceParser xpp = res.getXml(R.xml.test);xpp.next();int eventType = xpp.getEventType();while (eventType != XmlPullParser.END_DOCUMENT) {if(eventType == XmlPullParser.START_DOCUMENT) {sb.append("******Start document");} else if(eventType == XmlPullParser.START_TAG) {sb.append("\nStart tag "+xpp.getName());} else if(eventType == XmlPullParser.END_TAG) {sb.append("\nEnd tag "+xpp.getName());} else if(eventType == XmlPullParser.TEXT) {sb.append("\nText "+xpp.getText());}eventType = xpp.next();}//eof-whilesb.append("\n******End document");return sb.toString(); RawFile Resources r = activity.getResources();InputStream is = r.openRawResource(R.raw.test);String myText = convertStreamToString(is);is.close();return myText; convertStreamToString ByteArrayOutputStream baos = new ByteArrayOutputStream();int i = is.read();while (i != -1){baos.write(i);i = is.read();}return baos.toString(); getStringFromAssetFile AssetManager am = activity.getAssets();InputStream is = am.open("test.txt");String s = convertStreamToString(is);is.close();return s;?
轉載于:https://www.cnblogs.com/vijay/p/3531348.html
總結
以上是生活随笔為你收集整理的Android-----Resources的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 预留创建时检查增强点:nbsp;MB_R
- 下一篇: Android MVC模式在androi