Abdalrahman Shatou
Abdalrahman Shatou

Reputation: 4758

Styleable cannot be resolved

Here is the code I am using:

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();
       }
}

Here is the attrs.xml file (added to values folder):

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

The answers in these questions couldn't fix the problem. Please don't consider my question as duplicate.


Update: It seems that I was importing the wrong R class. It shall be the application's R class not android.R.

Upvotes: 6

Views: 4513

Answers (2)

Tin Luu
Tin Luu

Reputation: 1687

Check your imports:

  • Wrong: Android.R
  • Correct: com.example.yourproject.R

I had the same error when made this customized view. Maybe when follow the guiding step, the helper tool automatically inserts this wrong import.

Upvotes: 5

Abdalrahman Shatou
Abdalrahman Shatou

Reputation: 4758

It seems that I was importing the wrong R class. It shall be the application's R class not android.R

Upvotes: 2

Related Questions