zoukankan      html  css  js  c++  java
  • Android-----Resources

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

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

    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);
    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("
    Start tag "+xpp.getName());
                } 
                else if(eventType == XmlPullParser.END_TAG) {
                    sb.append("
    End tag "+xpp.getName());
                } 
                else if(eventType == XmlPullParser.TEXT) {
                    sb.append("
    Text "+xpp.getText());
                }
                eventType = xpp.next();
            }//eof-while
            sb.append("
    ******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;
  • 相关阅读:
    ylbtech-LanguageSamples-Indexers_2(索引器)
    ylbtech-LanguageSamples-Indexers(索引器)
    ylbtech-LanguageSamples-Hello World
    ylbtech-LanguageSamples-Generics(泛型)
    Tomcat
    Tomcat中部署WEB项目的四种方法
    解决fonts.gstatic.com无法访问
    关于android的屏幕保持常亮
    求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
    不用加减乘除实现加法
  • 原文地址:https://www.cnblogs.com/vijay/p/3531348.html
Copyright © 2011-2022 走看看