在库22中使用什么代替getSupportActionBar()? [英] What to use instead of getSupportActionBar() in Library 22?
本文介绍了在库22中使用什么代替getSupportActionBar()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码中有一行标记为黄色:
There is a line in my code, that marked as yellow:
getSupportActionBar().setDisplayShowHomeEnabled(true);
安装 appcompat-v7:22.1 后,它会显示提示:
After installing appcompat-v7:22.1 it shows a hint:
方法调用可能会产生java.lang.nullpointerexception。
"Method invocation may produce java.lang.nullpointerexception".
应该使用什么代替 getSupportActionBar()
?
推荐答案
getSupportActionBar().setDisplayShowHomeEnabled(true);
应该说
if (getSupportActionBar() != null)
{
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
getSupportActionBar()可以返回null,因此提示告诉您有关情况。
getSupportActionBar() can return null so you the hint is telling you about this.
这篇关于在库22中使用什么代替getSupportActionBar()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文