通话要求 API 16 级(当前最低为 14 级)
Call requires API level 16 (current min is 14)
我的代码中有这一行:
linearLayout.setBackground(drawable);
setBackground()
显示以下错误:
Call requires API level 16 (current min is 14)
这是什么意思?
我可以提高 API 等级吗?
higher/lower API 级别是什么意思?
如果 API 级别更高,它会限制我的应用程序可以使用的设备数量吗?
What does this mean?
意思是setBackground(Drawable)
方法是在API16级加入的,老机型没有。但是,您的应用的 minSdkVersion
是 14。因此,除非您采取措施避免在 API 级别 14 和 15 设备上出现此行,否则您的应用将在这些设备上崩溃。
Can I raise my API level?
您可以将 minSdkVersion
设置为 16。
Does it limit the amount of devices my app can be used on if the API level is higher?
是的。如果您说您的 minSdkVersion
是 16,那么设备 运行 的 Android 版本早于该 运行 就不能 运行 您的应用程序。
在撰写本文时,about 90% of Android devices accessing the Play Store are on API Level 16 or higher(即 运行ning Android 4.1 或更高)。
您可以在 the documentation 中阅读有关 API 级别概念的更多信息。请注意,此文档有点旧,因为它侧重于清单中定义的 minSdkVersion
。在 Android Studio 项目中,minSdkVersion
通常在 app
模块的 build.gradle
文件中定义。
Can I raise my API level?
您可以将 API 设置为 16,它会将设备限制在 16 以下,但它会在设备 API 16 及更高
上完美运行
Or else You can use API check and set
final int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
layout.setBackgroundDrawable( getResources().getDrawable(R.drawable.ready) );
} else {
layout.setBackground( getResources().getDrawable(R.drawable.ready));
}
使用仅在 API LEVEL >= 16 中支持的验证方法(注意使用 ContextCompat class:
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
linearLayout.setBackground(ContextCompat.getDrawable(this, drawableid));
}
使用:
layout.setBackgroudResource(R.drawable.ready);
我的代码中有这一行:
linearLayout.setBackground(drawable);
setBackground()
显示以下错误:
Call requires API level 16 (current min is 14)
这是什么意思?
我可以提高 API 等级吗?
higher/lower API 级别是什么意思?
如果 API 级别更高,它会限制我的应用程序可以使用的设备数量吗?
What does this mean?
意思是setBackground(Drawable)
方法是在API16级加入的,老机型没有。但是,您的应用的 minSdkVersion
是 14。因此,除非您采取措施避免在 API 级别 14 和 15 设备上出现此行,否则您的应用将在这些设备上崩溃。
Can I raise my API level?
您可以将 minSdkVersion
设置为 16。
Does it limit the amount of devices my app can be used on if the API level is higher?
是的。如果您说您的 minSdkVersion
是 16,那么设备 运行 的 Android 版本早于该 运行 就不能 运行 您的应用程序。
在撰写本文时,about 90% of Android devices accessing the Play Store are on API Level 16 or higher(即 运行ning Android 4.1 或更高)。
您可以在 the documentation 中阅读有关 API 级别概念的更多信息。请注意,此文档有点旧,因为它侧重于清单中定义的 minSdkVersion
。在 Android Studio 项目中,minSdkVersion
通常在 app
模块的 build.gradle
文件中定义。
Can I raise my API level?
您可以将 API 设置为 16,它会将设备限制在 16 以下,但它会在设备 API 16 及更高
上完美运行Or else You can use API check and set
final int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
layout.setBackgroundDrawable( getResources().getDrawable(R.drawable.ready) );
} else {
layout.setBackground( getResources().getDrawable(R.drawable.ready));
}
使用仅在 API LEVEL >= 16 中支持的验证方法(注意使用 ContextCompat class:
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
linearLayout.setBackground(ContextCompat.getDrawable(this, drawableid));
}
使用:
layout.setBackgroudResource(R.drawable.ready);