demibug

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            24 Posts :: 3 Stories :: 2 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(5)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          轉自 http://happyin1111.blog.163.com/


          Drawable currentIcon = null;

          currentIcon = getResources().getDrawable(R.drawable.folder);

          currentIcon = getResources().getDrawable(R.drawable.image);

          把資源文件放到應用程序的/raw/raw下,那么就可以在應用中使用getResources獲取資源后,以openRawResource方法(不帶后綴的資源文件名)打開這個文件。例如:

          Resources myResources = getResources();
          InputStream myFile = myResources.openRawResource(R.raw.myfilename);

          和傳統的java文件操作一樣,在android Api中提供了openFileInput和openFileOutput方法來讀取設備上的文件。

          簡寫
          InputStream fs =this.getResources().openRawResource(R.raw.kb); (資源文件名為kb.html, 不需要帶后綴.html)
          InputStreamReader read = new InputStreamReader (fs,”gb2312″);
          BufferedReader in = new BufferedReader(read);

          讀取res/drawable目錄下的png或者bmg
          //得到Resources對象
          Resources r = this.getContext().getResources();
          //以數據流的方式讀取資源
          Inputstream is = r.openRawResource(R.drawable.my_background_image);
          BitmapDrawable bmpDraw = new BitmapDrawable(is);
          Bitmap bmp = bmpDraw.getBitmap();

          或者

          InputStream is = getResources().openRawResource(R.drawable.icon);
          Bitmap mBitmap = BitmapFactory.decodeStream(is);
          Paint mPaint = new Paint();
          canvas.drawBitmap(mBitmap, 40, 40, mPaint);

          數據包package:android.content.res
          主要類:Resources

          InputStream openRawResource(int id) 獲取資源的數據流,讀取資源數據

          把 一個圖片資源,添加你的文件到你工程中res/drawable/目錄中去,從這里,你就可以引用它到你的代碼或你的XML布局中,也就是說,引用它也可 以用資源編號,比如你選擇一個文件只要去掉后綴就可以了(例如:my_image.png 引用它是就是my_image)。

          posted on 2011-05-09 16:30 Hiji 閱讀(1254) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 呼伦贝尔市| 洛阳市| 汝州市| 中西区| 九江县| 昌邑市| 定襄县| 江口县| 阜南县| 洪雅县| 卢龙县| 汝南县| 台东市| 柳林县| 葫芦岛市| 惠安县| 东方市| 贺兰县| 咸阳市| 宜兰市| 德江县| 米林县| 罗定市| 南昌市| 清河县| 那曲县| 胶州市| 赤峰市| 石渠县| 永新县| 河北省| 精河县| 浠水县| 洛南县| 长乐市| 连平县| 河北省| 梨树县| 丹阳市| 桃江县| 邓州市|