6

I know that programatically I can use

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

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?

1
  • No, you cant do that, at least not easily, theres no conditional statement for xml files, maybe you can find a way to make the app use the watermarked xmls like it does for different density but im unsure. you should just do it by code. Commented Nov 24, 2015 at 9:29

1 Answer 1

6

It's possible now with the Data Binding Library.

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>

Then just use it like this:

<ImageView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:visibility="@{buildConfig.DEBUG ? View.VISIBLE : View.GONE}">
Sign up to request clarification or add additional context in comments.

4 Comments

After over five years :D
Actually, the data binding is available for some years. Unfortunately, I didn't see this question earlier. :)
As a note, this only works for layout files.
didn't work till i add buildFeatures { dataBinding true } in build.gradle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.