首页 > 移动平台 > 详细

Android-----Resources

时间:2014-01-24 02:01:41      阅读:418      评论:0      收藏:0      [点我收藏+]

    XML文件的读写方式基本上是利用DroidDraw,而且也很少有难的地方,复杂布局尽量用Relative,简单布局用LinearLayout,较为特殊的时候使用FrameLayot,另外两个AbsoluteLayout和TableLayout很少使用。  

记录一部分用Java实现的功能】

bubuko.com,布布扣
Image
     //Call getDrawable to get the image
        Drawable d = getResources().getDrawable(R.drawable.sample_image);
        //You can use the drawable then to set the background
        this.getTextView().setBackgroundDrawable(d);      
        //or you can set the background directly from the Resource Id
        this.getTextView().setBackgroundResource(R.drawable.sample_image);
bubuko.com,布布扣
Color
Resources res = this.mContext.getResources();
int mainBackGroundColor =  res.getColor(R.color.main_back_ground_color);
reportString("mainBackGroundColor:" + mainBackGroundColor);
bubuko.com,布布扣
ParseXML
bubuko.com,布布扣
     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-while
        sb.append("\n******End document");
        return sb.toString();
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣
RawFile
     Resources r = activity.getResources();
        InputStream is = r.openRawResource(R.raw.test);
        String myText = convertStreamToString(is);
        is.close();
        return myText;
bubuko.com,布布扣
bubuko.com,布布扣
convertStreamToString
bubuko.com,布布扣
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int i = is.read();
        while (i != -1){
            baos.write(i);
            i = is.read();
        }
        return baos.toString();
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣
getStringFromAssetFile
      AssetManager am = activity.getAssets();
        InputStream is = am.open("test.txt");
        String s = convertStreamToString(is);
        is.close();
        return s;
bubuko.com,布布扣

Android-----Resources

原文:http://www.cnblogs.com/vijay/p/3531348.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!