8

Attributes prefixed by "android" work fine, but how do I add the ones prefixed by something else?

For example, how can I add the following two attributes to the style bellow?

app:chipCornerRadius="20dp"
app:textStartPadding="8dp"

<style name="Chip" parent="Base.TextAppearance.AppCompat.Small">
    <item name="android:textSize">@dimen/smallTextSize</item>
    <item name="android:textColor">@color/black</item>
</style>
adriennoir
  • 1,329
  • 1
  • 15
  • 29
  • 7
    Just remove the `app:` prefix; e.g., `...`. – Mike M. Nov 25 '18 at 12:36
  • 1
    @MikeM. Using a style with the `app:` prefix removed does not work for the example above with `Chip`. – adriennoir Nov 25 '18 at 13:21
  • Then you've got some other issue. There is no other way to specify app-local attributes. Make sure you've got whichever library you're using added correctly, that you have the attribute names spelled correctly, and that you're using a version that actually offers those attributes. – Mike M. Nov 25 '18 at 13:24
  • @MikeM. It's about the `Chip` from the support library and the attributes are spelled correctly. The attributes work fine if I add them to a chip in my layout but will not work if I add them to a style and apply the style. – adriennoir Nov 25 '18 at 14:28
  • What exactly do you mean by "will not work"? Are you getting a build error, or a runtime error? – Mike M. Nov 25 '18 at 14:30
  • Btw, your `parent` style is wrong. It should be one of the `Widget.MaterialComponents.Chip.*` styles shown here: https://material.io/develop/android/components/chip/. – Mike M. Nov 25 '18 at 14:40
  • I was using it all wrong when applying the style. Thanks for your help! – adriennoir Nov 25 '18 at 15:09
  • Yeah, I kinda figured that was it, after I saw the `parent`. Sorry I didn't notice that right away. Glad you got it working. Cheers! – Mike M. Nov 25 '18 at 15:11

0 Answers0