0

I'm trying to change the background color of my Button when it's pressed so I'm creating a drawable resource file to customise the different button states.

I'm looking at an example xml file for this use case and I'm trying to understand what <item> and <selector> tags are - and what they're doing.

I've tried searching but couldn't find any explanations.

Zorgan
  • 8,227
  • 23
  • 106
  • 207
  • You can check the Docs [State list](https://developer.android.com/guide/topics/resources/drawable-resource) – AskNilesh Mar 18 '19 at 10:49

1 Answers1

0

<selector> and <item> are used when you are creating a custom button.

The <selector> tag is the root tag and it can contain multiple <item> tags, the only attribute it contains is the xmlns:android.

Example:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item> is used to define a color on different states of a component. You can find more information here:

https://developer.android.com/guide/topics/resources/color-list-resource

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • Thanks however I'm trying to change the background color not the text color - which is why the code snippet there is not compatable with `android:background` - I believe it needs to be nested in `` but I'm not sure where I can read more about this. – Zorgan Mar 18 '19 at 21:00
  • Check this https://stackoverflow.com/questions/3592780/selector-on-background-color-of-textview – Peter Haddad Mar 19 '19 at 04:53