【问题标题】:ActionBar custom layout like ICS edit contactActionBar 自定义布局,如 ICS 编辑联系人
【发布时间】:2013-07-30 15:02:28
【问题描述】:
我刚开始使用带有 ActionBar 支持的新支持库。我正在尝试实现一个看起来与编辑联系人屏幕上的冰淇淋三明治布局基本相同的栏。我知道我可能需要实现与此类似的自定义视图 - How to display custom view in ActionBar?。我不明白该视图到底是什么,以及实现它的最佳方式。
这是我想要在操作栏中显示的屏幕截图:
这只是一个带有图像和一些文本的视图,还是一个样式按钮,还是完全不同的东西?它有一些状态按下的属性。
感谢您的帮助。
【问题讨论】:
标签:
android
android-layout
android-actionbar
android-actionbar-compat
【解决方案1】:
您可以尝试使用自定义视图,当您希望按钮出现时添加以下代码:
// 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);