【发布时间】:2023-03-28 19:25:01
【问题描述】:
我目前在 android 中有一个 bool.xml 文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="showAds">true</bool>
</resources>
现在我有一个使用数据绑定的 layout.xml 文件。我想根据上面定义的布尔 showAds 显示或隐藏 adView 的可见性。到目前为止,我有这个:
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="@{@bool/showAds ? View.Visible:View:gone}"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-1234567/34343">
但它不会编译。我怎样才能得到布尔值来决定广告是否应该显示?语法错误。
【问题讨论】:
标签: android data-binding