ActionBar中如果需要显示一些用于导航的视图,则可以用setCustomView来设置:
actionBar.setCustomView(R.layout.customView);
但是使用之前必须显式的将它开启:
actionBar.setDisplayShowCustomEnabled(true);
否则会出现NullPointerException
本文介绍了如何在ActionBar中使用setCustomView方法显示自定义视图,并强调了在使用前需调用setDisplayShowCustomEnabled(true)以启用自定义视图功能,避免出现NullPointerException。
ActionBar中如果需要显示一些用于导航的视图,则可以用setCustomView来设置:
actionBar.setCustomView(R.layout.customView);
但是使用之前必须显式的将它开启:
actionBar.setDisplayShowCustomEnabled(true);
否则会出现NullPointerException
301

被折叠的 条评论
为什么被折叠?