简体   繁体   English

Android Call需要API级别13(当前最小值为10):android.view.Display #getSize

[英]Android Call requires API level 13 (current min is 10): android.view.Display#getSize

I'm trying to target as many architectures as possible, as well as having few warnings as possible. 我试图尽可能多地定位架构,并尽可能少地发出警告。

Point dims = new Point();
if (android.os.Build.VERSION.SDK_INT >= 13) {
      mWindowManager.getDefaultDisplay().getSize(dims);
} else if (android.os.Build.VERSION.SDK_INT < 13) {
  dims.x = mWindowManager.getDefaultDisplay().getWidth();
  dims.y = mWindowManager.getDefaultDisplay().getHeight();
}

But this gives me the error and warning: 但这给了我错误和警告:

Call requires API level 13 (current min is 10): android.view.Display#getSize
The method getWidth() from the type Display is deprecated

They say to change the manifesto (or here ) but why is this above not working for the compiler? 他们说改变宣言 (或这里 ),但为什么上面这个不适用于编译器? Can't I get rid of both with the range of apis 10 to 18 ? 难道我不能摆脱10到18的api范围吗?

You already have the SDK version checking in place so the deprecation warning from compiler and lint warning about new API can be ignored. 您已经对SDK版本进行了检查,因此可以忽略编译器的弃用警告和有关新API的lint警告。

Pull the code snippet to a separate method and add the following annotations to it: 将代码段拉到单独的方法并向其添加以下注释:

@TargetApi(13)
@SuppressWarnings("deprecation")

Note that the if part of your else if is redundant. 需要注意的是if你的一部分, else if是多余的。 Plain else is enough. 简单的else就够了。

To retrieve the display size, the recommended way is to use 要检索显示大小,建议使用的方法

context.getResources().getDisplayMetrics()

instead. 代替。 Then use the widthPixels and heightPixels properties. 然后使用widthPixelsheightPixels属性。

Using the current context gives you the dimensions of the current display in case of multiple displays, which is also safer. 使用当前上下文为您提供多个显示器当前显示的尺寸,这也更安全。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android在API级别13之前显示getSize() - Android display getSize() before API level 13 ?android:attr / selectableItemBackground`需要API级别11(当前最小值为10) - ?android:attr/selectableItemBackground` requires API level 11 (current min is 10) 调用需要API级别16(当前最小值为10):android.widget.ImageView#getMaxWidth - Call requires API level 16 (current min is 10): android.widget.ImageView#getMaxWidth 调用需要 API 级别 21(当前最小值为 19):android.view.View() - Call requires API level 21 (current min is 19): android.view.View() 调用需要API级别14(当前最小值为8):android.view.ViewGroup#canScrollHorizo​​ntally - Call requires API level 14 (current min is 8): android.view.ViewGroup#canScrollHorizontally 调用需要API级别14(当前最小值为10): - Call requires API level 14 (current min is 10): android - 调用需要API级别9(当前最小值为8):android.os.StrictMode #setThreadPolicy - android - Call requires API level 9 (current min is 8): android.os.StrictMode#setThreadPolicy 调用需要API级别11(当前最小值为8)android.app.Activity#onCreateView - Call requires API level 11(current min is 8) android.app.Activity#onCreateView 如何在Android Studio中为消息“调用要求API级别21(当前最小值为16)”启用lint错误? - How to enable lint error in Android Studio for message “Call requires API level 21 (current min is 16)”? 调用需要API级别11(当前最小值为8):android.app.Activity#onCreateView FragmentActivity - Call requires API level 11 (current min is 8): android.app.Activity#onCreateView FragmentActivity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM