如何创建自定义ActionBar?

时间:2014-03-04 15:36:26

标签: android android-actionbar

我正在尝试使用setCustomView创建自定义ActionBar,但是当应用加载时,默认ActionBar会在自定义视图之前加载,并且选项(菜单项)会自动添加到操作栏。

我需要像这样创建一个ActionBar:https://play.google.com/store/apps/details?id=com.homes.rentals

我该怎么做?

更新:

我正在使用ActionBar AppCompat支持库。

2 个答案:

答案 0 :(得分:0)

SherlockActionBar开始,使用支持极低API API-7的{​​{1}}库。该库允许您添加customActionBar UI图标并处理其操作。

从此link

下载SherlockActionBar

使用这个简单的tutorial来了解如何使用它。

答案 1 :(得分:0)

然后你怎么做自定义布局xml你想要它看起来像什么,然后像:

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
    LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.custom_action_bar, null);

actionBar.setCustomView(v);

编辑: 要从ActionBar中删除您的图标,请使用Java,在ActionBar上调用setDisplayShowHomeEnabled(false)setDisplayShowTitleEnabled(false)