如果 android 版本低于 "X",如何隐藏 ImageButton?

How to hide ImageButton if android version is under "X"?

实际上我正在为 android 中的服务员开发一个应用程序, 当我服务员登录时,我有两个 ImageButtons 可以扫描他们的徽章,所以如果 android 的版本 <= 21.

我就可以隐藏那个 ImageButtons

我怎样才能做出那样的东西?

使用Build.VERSION.SDK_INT。 21 的版本是 LOLLIPOP

    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
        //show button
    }else {
       // hide button
    }

确保使用以下导入

import android.os.Build;

使用

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){
// above version of 21
} else{
// lowversion of 21
}