XML中setTag(键,值)的等价性

Cem*_*emo 8 xml android view

我可以setTag(key)在我的Android布局文件中使用等价物,如下所示:

 <EditText android:id="@+id/passwordEdit"
         android:tag="key"
         android:inputType="textPassword"/>
Run Code Online (Sandbox Code Playgroud)

我想setTag(key, value)在我的xml中使用等价.

可能吗?

psy*_*kid 11

我在聚会上有点迟了......但是如果你使用的是api等级21或以上,你可以从xml做到这一点.我不确定内存泄漏问题是否仍然存在.

<Button
android:layout_width=match_parent
android:layout_height=wrap_content
android:text="New button" >
     <tag android:id="SomeId" android:value="SomeValue" />
</Button>
Run Code Online (Sandbox Code Playgroud)