首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Eclipse不显示我的自定义属性(attrs.xml)

Eclipse不显示我的自定义属性(attrs.xml)
EN

Stack Overflow用户
提问于 2011-07-04 20:43:06
回答 2查看 1.7K关注 0票数 0

使用Eclipse,我创建了一个简单的Android项目,其中包含一个自定义组件( android.widget.TextView).继承的MyTextView)在创建该文件后,attrs.xml向该类添加了一个属性,如下所示:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="MyTextView" >
        <attr name="AttributeOne" format="integer"/>
    </declare-styleable>
</resources>

我在我的main.xml线性布局中添加了一个对象:

代码语言:javascript
复制
<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,选择选项卡‘图形布局’,选择我的组件时,自定义属性不会出现在Eclipse的选项卡'Properties‘中,但是类继承的原始属性会出现。

这是个错误吗?提交自定义属性的过程是什么?还是我弄错了?

谢谢。卢西亚诺。

EN

回答 2

Stack Overflow用户

发布于 2013-05-31 11:40:47

我刚刚重新启动了Eclipse,它成功了!:D

票数 2
EN

Stack Overflow用户

发布于 2015-01-04 10:35:02

要允许Android开发工具与视图交互,至少必须提供一个构造函数,该构造函数以上下文AttributeSet对象作为参数。此构造函数允许布局编辑器创建和编辑视图的实例。

代码语言:javascript
复制
class PieChart extends View 
{
    public PieChart(Context context, AttributeSet attrs)  
    {
        super(context, attrs);
    }
}

如果仍未解决,则可以在自定义视图中这样做:

代码语言:javascript
复制
if(!isInEditMode())
{
   // Your custom code that is not letting the Visual Editor draw properly
   // i.e. thread spawning or other things in the constructor
}

isInEditMode的细节

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6575912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档