XML检测调试模式 [英] XML detect debug mode

查看:35
本文介绍了XML检测调试模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过编程方式使用

I know that programatically I can use

if (BuildConfig.DEBUG) {
  // do something for a debug build
}

但是,我想做的是在调试模式下显示水印.有没有办法在XML文件中执行类似的操作?

However, what I'd like to do is show a watermark when in debug mode. Is there a way to do something similar to this in the XML files?

推荐答案

现在可以使用首先,您必须为 BuildConfig 对象定义一个变量:

First, you have to define a variable for the BuildConfig object:

<data>
  <import type="android.view.View" />

  <variable
    name="buildConfig"
    type="your.app.domain.BuildConfig"/>
</data>

然后像这样使用它:

<ImageView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:visibility="@{buildConfig.DEBUG ? View.VISIBLE : View.GONE}">

这篇关于XML检测调试模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆