【发布时间】:2011-07-04 20:43:06
【问题描述】:
使用 Eclipse,我创建了一个简单的 Android 项目,其中包含一个自定义组件(MyTextView,继承自 android.widget.TextView)。 创建文件后,我在 attrs.xml 中向此类添加了一个属性,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyTextView" >
<attr name="AttributeOne" format="integer"/>
</declare-styleable>
</resources>
我在 main.xml 线性布局中添加了一个对象:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mt="http://schemas.android.com/apk/res/myprogram.custom"
android:orientation="vertical"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<myprogram.custom.MyTextView
android:text="MyTextView"
android:id="@+id/myTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</myprogram.custom.MyTextView>
</LinearLayout>
当我打开main.xml,选择'Graphical Layout'选项卡,选择我的组件,Eclipse的'Properties'选项卡中没有出现自定义属性,而是原来的类继承属性(android.widget.TextView)出现。
这是个错误?提交我的自定义属性的程序是什么?
还是我弄错了?
谢谢。 卢西亚诺。
【问题讨论】:
-
您是否尝试关闭您的项目并再次打开它?我注意到,除非我重新加载项目,否则 Eclipse 中的图形布局似乎不会更新(添加主题时)的主题。
-
是的,但还是不行……
标签: android xml eclipse custom-attributes