Home » Android » android – Equivalence of setTag(key, value) in XML

android – Equivalence of setTag(key, value) in XML

Posted by: admin June 15, 2020 Leave a comment

Questions:

I can use equivalence of setTag(key) at my Android layout files as this:

 <EditText android:id="@+id/passwordEdit"
         android:tag="key"
         android:inputType="textPassword"/>

I would like to use equivalence of setTag(key, value) at my xml.

Is it possible?

How to&Answers:

I’m a bit late to the party… but anyways you can do this from xml if you are using api level 21 or above. I am not sure whether the memory leak issue is still present or not.

<Button
android:layout_width=match_parent
android:layout_height=wrap_content
android:text="New button" >
     <tag android:id="SomeId" android:value="SomeValue" />
</Button>

Answer:

There is this:
<tag android:id="..." android:value="..."/>