1

这里是我使用的代码:设置样式不能得到解决

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:

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

在这些问题couldn的答案”解决问题。请不要认为我的问题是重复的。


更新:看来我导入了错误的R类。应用程序的R类不是android.R

回答

1

看来我输入了错误的R类。它应是应用程序的R类别不android.R

+0

如果这是答案,那么请接受您自己的答案,以帮助未来的访问者。这就是Stack Overflow的工作原理。请参阅[如何接受答案?](http://meta.stackexchange.com/q/5234/173448)。 – jww

0

检查进口:

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

我有同样的错误时,由该自定义视图。也许当遵循指导步骤时,帮助工具会自动插入这个错误的导入。

+0

@jww:感谢您的帮助 –