首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解决

无法解决
EN

Stack Overflow用户
提问于 2013-06-21 19:15:59
回答 2查看 4.3K关注 0票数 5

下面是我使用的代码:

代码语言:javascript
复制
public ASSwitch(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray sharedTypedArray = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.ASSwitch,
            0, 0);

       try {
           onText = sharedTypedArray.getText(R.styleable.ASSwtich_onText, null);

       } finally {
           sharedTypedArray.recycle();
       }
}

下面是attrs.xml文件(添加到values文件夹):

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="ASSwitch">
        <attr name="onText" format="string" />
        <attr name="offText" format="string" />
        <attr name="onState" format="boolean" />
        <attr name="toogleDrawable" format="string" />
        <attr name="frameDrawable" format="string" />
    </declare-styleable>
</resources>

这些问题的答案不能解决这个问题。请不要认为我的问题是重复的。

更新:似乎我导入了错误的R类。它应该是应用程序的R类,而不是android.R类。

EN

回答 2

Stack Overflow用户

发布于 2014-12-27 07:29:03

检查您的进口:

  • 错:Android.R
  • 正确:com.example.yourproject.R

在创建这个自定义视图时,我也犯了同样的错误。也许当遵循指导步骤时,助手工具会自动插入这个错误的导入。

票数 4
EN

Stack Overflow用户

发布于 2013-06-21 22:37:53

好像我引进了错误的R级。它应该是应用程序的R级,而不是android.R。

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

https://stackoverflow.com/questions/17242720

复制
相关文章

相似问题

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