`

在资源中引用资源

阅读更多

在资源中引用资源

 

你可以在其他XML资源中通过特性来引用资源。

 

这种方式特殊应用的地方是layoutstyle,用来按主题的方式创建特定的样子和定位字符串和图片。另外,它也有益于layout支持不同的图片和间隔,来优化不同的屏幕大小和分辨率。

 

引用其他的资源,使用“@”记号,如下面的片段所示:

 

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

 

Android假设你在相同的包内使用资源,如果你想引用其它包里的资源,只需要写全包名即可。

 

接下来的片段创建了一个layout,使用了颜色、尺寸和字符串资源:

 

<?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>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics