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

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

2013-7-10 19:52| 發佈者: woff| 查看: 853| 評論: 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, 2025-3-27 06:02 , Processed in 0.018403 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

返回頂部