Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML detect debug mode

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?

like image 910
Daniël van den Berg Avatar asked Nov 10 '22 01:11

Daniël van den Berg


1 Answers

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}">
like image 101
gabhor Avatar answered Nov 15 '22 06:11

gabhor