Search code examples
androidtextviewandroid-custom-viewandroid-custom-attributes

How to get attributes with namespace "android" in custom TextView


In custom TextView I'm trying to obtain value of a text attribute (for example).

TypedArray values = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.TextView);
String text = values.getString(com.android.internal.R.styleable.TextView_text);

But I'm getting this error message:

package com.android.internal.R does not exist

So how to retrieve "default" attributes of TextView?


Solution

  • The internal.R class isn't visible so you can only read them through their accessor methods and only once your super constructor has been called.

    See the TextView source to see how it works internally.