效果图:

1、activity_main.xml

  描述:

    定义两个按钮,一个是Raw资源管理,一个是处理国际化语言,其中i18n表示简体中文

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Raw资源管理"
android:onClick="test_5"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/i18n"
android:onClick="test_5"
/>
</LinearLayout>

2、MainActivity.java

  描述:

    页面跳转

package com.example.android_shaperesoucesdemo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }
public void test_5(View view){
Intent intent = new Intent(this,RawActivity.class);
startActivity(intent);
}
}

3、activity_raw.xml

   描述:

     定义两个按钮,一个实现读取Raw资源文件中的文本资源;一个实现读取Raw资源文件中的音频资源

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_raw"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/showMessage"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="读取Raw中文本资源"
android:onClick="readTxt"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="读取Raw中音频资源"
android:onClick="readMp3"
/>
</LinearLayout>

4、RawActivity.java

package com.example.android_shaperesoucesdemo;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView; import java.io.IOException;
import java.io.InputStream; public class RawActivity extends Activity {
private TextView showMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_raw);
showMessage = (TextView)findViewById(R.id.showMessage);
}
//读取文本资源
public void readTxt(View view){
     //定义一个输入流,读取raw文件中的hello文件
     //Android读取asserts和raw文件夹下的文件 经常需要用到读取“/res/raw”和"/asserts"文件夹下的文件
InputStream input = getResources().openRawResource(R.raw.hello);
try {
       //获取流的大小
int size = input.available();
       //将流转换为字节
byte[] bytes = new byte[size];
       //读出字节
input.read(bytes);
input.close();
       //将字节转换成字符串显示在UI界面上
showMessage.setText(new String(bytes));
} catch (IOException e) {
e.printStackTrace();
}
}
  //定义一个读取MP3文件资源的方法
public void readMp3(View view) throws IOException{
     //MediaPlayer是播放音频和视频的组件
     //通过组件获取raw中的音乐文件nobody
MediaPlayer mp = MediaPlayer.create(this,R.raw.nobody);
     //开始播放音乐
mp.start();
}
}

5、res目录下创建一个raw包,在包中创建一个文本文件hello.txt,并在包中放一首音乐nobody.mp3

在hello.txt文件中随便输入一些内容

6、处理国际化:

  在res资源目录下创建一个values-zh-rCN的包,包中创建一个String.xml文件 

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Android_Resouces_2</string> <!--定义字符串-->
<string name="i18n">国际化</string>
</resources>

  在main目录下创建一个assets的资源目录

    然后在assets目录下放入一个SIMKAL.TTF文件,这个文件是简体中文

    文件下载地址:http://www.font5.com.cn/zitixiazai/1/534.html

Android开发 ---如何操作资源目录中的资源文件5 ---Raw资源管理与国际化的更多相关文章

  1. Android开发---如何操作资源目录中的资源文件4 ---访问xml的配置资源文件的内容

    Android开发---如何操作资源目录中的资源文件4 XML,位于res/xml/,这些静态的XML文件用于保存程序的数据和结构. XmlPullParser可以用于解释xml文件 效果图: 描述: ...

  2. Android开发---如何操作资源目录中的资源文件3--圆角边框、背景颜色渐变效果、边框颜色

    Android开发---如何操作资源目录中的资源文件3 效果图 1.圆角边框 2.背景颜色渐变效果 1.activity_main.xml 描述: 定义了一个shape资源管理按钮 <?xml ...

  3. Android开发 ---如何操作资源目录中的资源文件2

    Android开发 ---如何操作资源目录中的资源文件2 一.颜色资源管理 效果图: 描述: 1.改变字体的背景颜色 2.改变字体颜色 3.改变按钮颜色 4.图像颜色切换 操作描述: 点击(1)中的颜 ...

  4. Android开发---如何操作资源目录中的资源文件

    效果图: 1.activity_main.xml <?xml version="1.0" encoding="utf-8"?> <Linear ...

  5. android开发之-查看、编辑手机sqlite数据库文件-实测

    效果图: 1.开始——运行——输入cmd ,输入adb shell,错误:一是“adb不是内部命令或外部命令,也不是可运行的程序或批处理文件”,二是“error:device not found”. ...

  6. 在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world

    一.题目 编写一个内核模块,在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world.内核版本要求2.6.18 二.实验环境 物理主机:w ...

  7. 创建一个目录info,并在目录中创建一个文件test.txt,把该文件的信息读取出来,并显示出来

    /*4.创建一个目录info,并在目录中创建一个文件test.txt,把该文件的信息读取出来,并显示出来*/ #import <Foundation/Foundation.h>#defin ...

  8. python实现在目录中查找指定文件的方法

    python实现在目录中查找指定文件的方法 本文实例讲述了python实现在目录中查找指定文件的方法.分享给大家供大家参考.具体实现方法如下: 1. 模糊查找 代码如下: import os from ...

  9. 如何查找一个目录中所有c文件的总行数

    如何查找一个目录中所有c文件的行数 面试题问到了一题,如何统计wc文件夹下所有文件的行数,包括了子目录. 最后在 https://blog.csdn.net/a_ran/article/details ...

随机推荐

  1. 20165327 2017-2018-2 《Java程序设计》第4周学习总结

    20165327 2017-2018-2 <Java程序设计>第4周学习总结 教材内容总结 第五章 继承是一种由已有的类创建新类的机制. class 子类名 extends 父类名{ - ...

  2. linux文件管理之解压缩

    文件的压缩与解压缩 Linux文件压缩工具有:gzip.bzip2.rar.7zip.lbzip2.xz.lrzip.PeaZip.arj等.============================= ...

  3. android -------- 我创建的第一个 NDKDmeo 案例

    前面的NDK是弄的官方的,自己弄了一下,弄让他运行起来,今天来简单的写一个. 我是在Eclipse中开发的,创建一个NDKDemo项目,然后如下图: 在项目上–>右键–>Android T ...

  4. 使用xshell远程连接

    xshell 是一个强大的安全终端模拟软件,它支持SSH1,SSH2以及microsoft windows 平台的TELNET协议.xshell通过互联网到远程主机的安全连接. xshell可以在wi ...

  5. Tempter of the Bone HDU - 1010

    The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it u ...

  6. Permutations CodeForces - 736D (矩阵逆)

    对于删除每个对(x,y), 可以发现他对答案的贡献为代数余子式$A_{xy}$ 复习了一下线代后发现代数余子式可以通过伴随矩阵求出, 即$A_{xy}=A^*[y][x]$, 伴随矩阵$A^*=|A| ...

  7. oracle数据库静态监听配置示例

    [oracle@Oracle11g admin]$ cat listener.ora SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =     (GLOB ...

  8. UI基础四:简单的assign block

    经常会有需求让在标准的order加个assign block,那就来简单说一下: 1.创建assign block组件ZXXXXXX 2.添加BTORDER节点和GUID属性 3.创建表视图(可配置, ...

  9. Mybatis 查询tinyint(1)的数据库字段时会自动转换成boolean类型

    解决方案:将字段的tinyint(1)变成tinyint(2)

  10. python中类的概念

    在Python中,所有数据类型都可以视为对象,也可以自定义对象.自定义的对象即面向对象中的类(Class)的概念. class Student(object): def __init__(self, ...