我试图在我的应用程序中的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之前内部使用?