“调用需要API级别23”错误,但是来自API 1的FrameLayout上存在getForeground() [英] 'Call requires API level 23' error, but getForeground() exists on FrameLayout from API 1
问题描述
摘要
最后,我找到了相关问题, setForeground()
错误地标记为要求ViewGroups上的API 23扩展 FrameLayout
。
新问题
所以我的问题改为如何使用以前版本中的方法,以及为什么会有选择地出现检查错误?
如果我添加了多余的强制转换,错误消息就会消失:
((FrameLayout)布局).getForeground()
但它是访问现在不支持的查看
方法。
所以我认为定位以前的API会删除错误消息但我很感激使用这种Framelayout方法的解决方案或线索来解决我的问题:
ANDROID_COMPILE_SDK_VERSION = 23
ANDROID_BUILD_TOOLS_VERSION = 23.0.1
ANDROID_DEFAULT_MIN_SDK_VERSION = 19
ANDROID_DEFAULT_TARGET_SDK_VERSION = 23
解决方法
简而言之,作为解决方法,我将类型更改为 FrameLayout
直接,所以关于API和铸造的警告都消失了,我测试它适用于Android 4.4.4设备和调试,我认为它会崩溃,无论如何它只用于动画,我将在未来修复/替换它。
初步问题
我分叉并自定义了Google示例
但在旧版本上调用新方法检查
显示需要API级别23的错误:
我找到了相似的问题,在这种情况下的一个错误,但我认为这不是一个由于原来的错误fork没有显示此错误消息。
我会尝试检测消息第一次出现,但我做了很多更改,所以任何线索都会受到赞赏,谢谢。
最后我找到了相关的问题, setForeground()
错误地标记为需要API 23 for Vie wGroups扩展 FrameLayout
。
问题189041:setForeground()被错误地标记为要求ViewGroups的API 23(NewApi)扩展FrameLayout
如果你没有扩展 FrameLayout
,文档错误,确实需要API 23。
问题186273:View.setForeground错误的API级别
Summary
Finally, I found the related issue, setForeground()
incorrectly flagged as requiring API 23 on ViewGroups extending FrameLayout
.
If you are not extending FrameLayout
, the documentation is wrong and API 23 is required.
Issue 186273: View.setForeground wrong API level
Updated question
Marked as duplicated of Can't use setForeground
method on ImageView by Commonsware and answered by him:
That is a documentation bug. setForeground() existed on FrameLayout from API Level 1; it is only on View as of API Level 23.
In my case the documentation bug is not detected by the inspection in the fork but does it in an integration project, I don't understand it, anyway, this answers my initial question.
But It's not the same case, this code is already extending a Framelayout
and using this method, it's not an ImageView
, so I suppose the method has been removed in API 23. It doesn't appear in the reference now.
Update: I add a diff report for FrameLayout:
New question
So my question changes to how to use the method in previous versions, and, why does appear the inspection error selectively?
If I add a redundant cast, the error message disappears:
((FrameLayout) layout).getForeground()
But it's accessing the View
method that is not supported now.
So I suppose targeting a previous API would remove the error message but I would appreciate a solution to use this Framelayout method or a clue to fix the issue in my case:
ANDROID_COMPILE_SDK_VERSION=23
ANDROID_BUILD_TOOLS_VERSION=23.0.1
ANDROID_DEFAULT_MIN_SDK_VERSION=19
ANDROID_DEFAULT_TARGET_SDK_VERSION=23
Workaround
In short, as a workaround, I changed the type to FrameLayout
directly, so warnings about API and casting are gone, and I tested it works on Android 4.4.4 device and debugging, I thought it would crash, anyway it's only used in one animation, and I will fix/replace it in the future.
Initial question
I forked and customised the Google sample android-topeka, and android-studio shows an error that I don't understand about the API level required to use the method getForeground()
of the class View
in android.view
package:
Call requires API level 23 (current min is 19): android.view.View#getForeground
The reference marks the method as added in API level 1, and the documentation (Control+Q
) shows the same:
But the Calling new methods on older versions inspection
shows an error that API level 23 is required:
I found a similar question, a bug in that case, but I think this is not a bug due to the original fork doesn't show this error message.
I'll try to detect the first time the message appears, but I did a lot of changes so any clue would be appreciated, thanks.
Finally I found the related issue, setForeground()
incorrectly flagged as requiring API 23 for ViewGroups extending FrameLayout
.
If you are not extending FrameLayout
, the documentation is wrong and API 23 is really required.
Issue 186273: View.setForeground wrong API level
这篇关于“调用需要API级别23”错误,但是来自API 1的FrameLayout上存在getForeground()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!