R.styleable can not be resolved, why?

后端 未结 6 1840
猫巷女王i
猫巷女王i 2020-12-03 16:58

I have a resources.xml file located under direcotry values/ , That\'s

/values/resources.xml



        
相关标签:
6条回答
  • 2020-12-03 17:35

    You can access your package level stylable like this

    <yourpackagename>.R.styleable.name
    
    0 讨论(0)
  • 2020-12-03 17:37

    I had an undefined styleable error showing in Android Studio, but then I noticed the build was successful. I did Invalidate Caches & Restart and the problem went away.
    (It took me far too long to figure it out.)

    0 讨论(0)
  • 2020-12-03 17:43

    According to the SDK Release Notes,

    The android.R.styleable class and its fields were removed from the public API, to better ensure forward-compatibility for applications. The constants declared in android.R.styleable were platform-specific and subject to arbitrary change across versions, so were not suitable for use by applications. You can still access the platform's styleable attributes from your resources or code. To do so, declare a custom resource element using a in your project's res/values/R.attrs file, then declare the attribute inside. For examples, see "sdk"/samples/ApiDemos/res/values/attrs.xml. For more information about custom resources, see Custom Layout Resources. Note that the android.R.styleable documentation is still provided in the SDK, but only as a reference of the platform's styleable attributes for the various elements.

    Have a look to the ApiDemos code and the file res/values/attrs.xml

    0 讨论(0)
  • 2020-12-03 17:50

    plz make values/attrs.xml resources like this

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <declare-styleable name="**com.admob.android.ads.AdView**"><--- where u want to use
           <attr name="backgroundColor" format="color" />
           <attr name="TextColor" format="color" />
           <attr name="keywords" format="string" />
           <attr name="refreshInterval" format="integer" />
        </declare-styleable>
    </resources>
    
    0 讨论(0)
  • 2020-12-03 17:51

    What you need to do is declare your styleable in attrs.xml, not resources.xml. Then you'll be able to refer to it from your code like this:

    R.styleable.TheMissingTabWidget
    
    0 讨论(0)
  • 2020-12-03 17:52

    In my case I had inadvertently done import android.R instead of import com.<mypackage>.R.

    Replace <mypackage> with your package name (or just delete the current import and let Android Studio do the rest).

    0 讨论(0)
提交回复
热议问题