软件编程
位置:首页>> 软件编程>> Android编程>> Android中资源文件用法简单示例

Android中资源文件用法简单示例

作者:无忧一生  发布时间:2023-09-24 22:29:04 

标签:Android,资源文件

本文实例讲述了Android中资源文件用法。分享给大家供大家参考,具体如下:

一、XML文件间资源文件的使用

引用格式:


attribute="@[packagename:]resourcetype/resourceidentifier"

example:

有strings.xml、color.xml、dimen.xml文件,使用其中的参数


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="@dimen/standard_border">
<EditText
android:id="@+id/myEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/stop_message"
android:textColor="@color/opaque_blue"
/>
</LinearLayout>

二、使用系统的资源

使用android本地系统资源要这样写:

CharSequence httpError = getString(android.R.string.httpErrorBadUrl);


在XML文件中的使用方法:


<EditText
android:id="@+id/myEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@android:string/httpErrorBadUrl"
android:textColor="@android:color/darker_gray"
/>

注意引用本地资源的文件的时候都加了android这个前缀。

希望本文所述对大家Android程序设计有所帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com