TShopping

 找回密碼
 註冊
搜索
TShopping 精選文章 Android 手機開發 查看內容

Android智慧型手機設計_resources:存取res目錄內的資源

2013-7-10 19:52| 發佈者: woff| 查看: 764| 評論: 0|原作者: woff

摘要: 1.設計string.xml ?xml version=1.0 encoding=utf-8? resources string name=app_nameCh7_2_Resource/string string name=action_settingsSettings/string string name=hello_worldresources:存取res目錄內的資源/s ...
 

1.jpg

1.設計string.xml




  1. Ch7_2_Resource
  2. Settings
  3. resources:存取res目錄內的資源

  4. 杜仲教學Android程式設計2013年

復制代碼



2.設計Ch7_2_Resource.java
  1. package com.example.ch7_2_resource;

  2. import android.media.MediaPlayer;
  3. import android.os.Bundle;
  4. import android.app.Activity;
  5. import android.content.res.Resources;
  6. import android.widget.ImageView;
  7. import android.widget.TextView;

  8. public class Ch7_2_Resource extends Activity {
  9. TextView tv1,tv2,tv3;
  10. ImageView IV;
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.main);
  15. tv1=(TextView)findViewById(R.id.tv1);
  16. tv2=(TextView)findViewById(R.id.tv2);
  17. tv3=(TextView)findViewById(R.id.tv3);
  18. IV=(ImageView)findViewById(R.id.imageView1);

  19. CharSequence cs=getText(R.string.style_text);
  20. tv1.setText(cs);
  21. String s=getString(R.string.style_text);
  22. tv2.setText(s);
  23. Resources r=getResources();
  24. cs=r.getText(R.string.style_text);
  25. tv3.setText(cs);
  26. IV.setImageResource(R.drawable.baby2);
  27. MediaPlayer MP=MediaPlayer.create(Ch7_2_Resource.this, R.raw.ring);
  28. MP.start();
  29. }
  30. }
復制代碼


最新評論



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-5-6 07:52 , Processed in 0.051319 second(s), 21 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

返回頂部