Android ActionBarSherlock在启用SetDisplayShowCustom的情况下不显示自定义视图
我正在使用ActionBarSherlock,有一个带有多个选项卡的应用程序。在其中一个选项卡中,我试图使用Android ActionBarSherlock在启用SetDisplayShowCustom的情况下不显示自定义视图,android,actionbarsherlock,Android,Actionbarsherlock,我正在使用ActionBarSherlock,有一个带有多个选项卡的应用程序。在其中一个选项卡中,我试图使用setDisplayShowCustomEnabled(true)显示SearchView 由于搜索应该只出现在其中一个选项卡中,因此当该选项卡可见时,我调用setDisplayShowCustomEnabled(true)当另一个选项卡变为可见时,我调用setDisplayShowCustomEnabled(false)以隐藏搜索 这在Android 4+(当使用stock Action
setDisplayShowCustomEnabled(true)显示SearchView
代码>
由于搜索应该只出现在其中一个选项卡中,因此当该选项卡可见时,我调用setDisplayShowCustomEnabled(true)代码>当另一个选项卡变为可见时,我调用setDisplayShowCustomEnabled(false)
以隐藏搜索
这在Android 4+(当使用stock ActionBar时)上运行良好,但在旧版本(当使用替代品时)上不起作用。在深入研究之后,似乎在其余选项卡中我显示了一个标题。似乎同时显示标题和自定义视图并不能很好地发挥作用-由于某种原因,当您这样做时,两者都被隐藏了,您最终什么也看不到
修正:
当“搜索”选项卡可见时:
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowCustomEnabled(false);
当另一个选项卡可见时:
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowCustomEnabled(false);
因此,解决办法是相应地隐藏标题
这只在旧的Android版本中需要,因为它在Android 4上没有标题部分+