ActionBar自定义布局,如ICS编辑联系人

时间:2013-07-30 15:02:29

标签: android android-layout android-actionbar android-actionbar-compat

我刚刚开始使用支持ActionBar的新支持库。我正在尝试实现一个看起来与编辑联系人屏幕上的冰淇淋三明治布局基本相同的栏。我知道我可能需要实现与此类似的自定义视图 - How to display custom view in ActionBar?。我不明白的是这种观点究竟是什么,以及实现它的最佳方式。

以下是我在操作栏中想要的屏幕截图:

enter image description here

这只是一个带有图像和一些文字的视图,或者是一个风格的按钮,还是完全不同的东西?它有一些状态压缩属性。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您可以尝试使用自定义视图,方法是在希望按钮显示时添加以下代码:

// Inflate the view from XML file
LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.search, null);

// Tell the view to occupy the whole actionBar view (MATCH_PARENT)
LayoutParams layout = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
getActionBar().setCustomView(v, layout);