如何在每个API级别对视图进行数据绑定? [英] How to data-bind views per API level?

查看:73
本文介绍了如何在每个API级别对视图进行数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不是显示生物识别登录按钮的要求是< API级别26,因为它不受支持,因此可以被隐藏. .setVisibility(View.GONE)方法不是一个选项,因为数据绑定应自行配置所有视图.

The requirement is not to display a bio-metric login button < API level 26 , because it isn't supported and therefore can be hidden for certain. method .setVisibility(View.GONE) is not an option, because the data-binding should configure the view all by itself.

推荐答案

一个人必须导入android.os.Build.VERSIONandroid.view.View,以便在生成的数据绑定中使用变量VERSION.SDK_INT和类View常量课程:

one has to import android.os.Build.VERSION and android.view.View, in order to have variable VERSION.SDK_INT and class View constants available in the generated data-binding classes:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android">

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

    <!-- only visible on API >= 26 -->
    <androidx.appcompat.widget.AppCompatImageView
        android:visibility="@{VERSION.SDK_INT >= 26 ? View.VISIBLE : View.GONE}"
        android:id="@+id/button_biometric_authentication"
        android:src="@drawable/ic_fingerprint_white_36dp"
        android:layout_gravity="center_vertical|end"
        android:layout_height="match_parent"        
        android:layout_width="wrap_content"/>

</layout>

这篇关于如何在每个API级别对视图进行数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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