方法View.getForeground()需要api 23

时间:2017-05-28 16:29:38

标签: android android-api-levels

我试图在我的应用程序中的AppCompatImageView上设置前景,但android studio告诉我getForeground()setForeground方法需要api 23.我认为这是一点点奇怪的是看起来很简单,所以我检查了this链接上的引用,发现方法getForeground已添加到api 1中。

所以,认为这只是Android工作室中的某种错误,我在api 19上启动了我的Nexus 5x模拟器来检查。当我点击我的视图(触发设置前景)时,应用程序崩溃了,给了我methodnotfoundexception

这对我来说有点混乱,因为很明显api 19没有这种方法,否则我的应用程序不会崩溃,文档很清楚地说明前景在api 1中添加了View类中的方法。此外,我可以在没有android studio抱怨的情况下在我的活动的XML中设置前景,但是在api 19中,前景实际上并没有显示出来。这是否意味着前景方法仅供api 23之前内部使用?

1 个答案:

答案 0 :(得分:1)

这是a known documentation bug。这些方法是在Android 6.0(API Level 23)中引入的。