【发布时间】:2011-07-08 07:35:01
【问题描述】:
我有一个正在尝试运行的 android 示例。 有两种方法可以做到这一点..
// Get a drawable
ColorDrawble redDrawable = (ColorDrawable).getResources().getDrawable(R.drawable.red_rectangle);
//Set it as a background to a text view
textView.setBackground(redDrawable);
当我把它放在 Eclipse IDE 中时,我得到一个错误 ColorDrawble cannot be resolve to a type 我在主 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"
>
<TextView android:layout_width="fill_parent"
android:id="@+id/texter"
android:layout_height="wrap_content"
android:text="this string"/>
</LinearLayout>
以及字符串xml文件中的资源
<resources>
<string name="hello">Hello World, ResourceTesterActivity!</string>
<string name="app_name">ResourceTester</string>
<drawable name="red_rectangle" >#f00</drawable>
<drawable name="blue_rectangle">#0000ff</drawable>
<drawable name="green_rectangle" >#f0f0</drawable>
</resources>
**
【问题讨论】:
-
为什么要将可绘制资源存储在strings.xml中?
-
它来自一个 adndroid 示例..来自 PRO android 2 amazon.com/Pro-Android-Sayed-Y-Hashimi/dp/1430226595