【问题标题】:can i access variables in xml file?if yes then how?我可以访问 xml 文件中的变量吗?如果是,那么如何?
【发布时间】:2013-10-02 02:28:44
【问题描述】:

我为安卓平台编写了代码。 我在 .java 文件中声明变量 sound_on_state 整数变量 在我的 sound.xml 中,我编写了以下代码,

enter code here
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"                           
       android:oneshot="false">
<xsl:if sound_on_state > 0> /*this line give error as android prefix namespace*/
<item android:drawable="@drawable/sound_on_02" android:duration="50"/>
<item android:drawable="@drawable/sound_on_01" android:duration="50"/>
<xsl:else>
<item android:drawable="@drawable/sound_off_02" android:duration="50"/>
<item android:drawable="@drawable/sound_off_01" android:duration="50"/>
</xsl:else>
</xsl:if>
</animation-list>

【问题讨论】:

    标签: java android xml


    【解决方案1】:

    不,你不能。应该从代码中完成。将视图块添加到布局,给它一个 ID,然后在代码中根据您想要的任何条件更改其可见性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-26
      • 2013-12-29
      • 1970-01-01
      • 2021-08-20
      • 1970-01-01
      • 2011-03-15
      • 1970-01-01
      相关资源
      最近更新 更多