恢复默认动作条的布局 [英] Restore default actionbar layout

查看:106
本文介绍了恢复默认动作条的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应用自定义查看动作条,像这样

I apply a custom View to the ActionBar, like this

// Inflate the "Done/Discard" custom ActionBar view.
LayoutInflater inflater = (LayoutInflater) DetailsHost.mActionBar
        .getThemedContext().getSystemService(DetailsHost.LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater.inflate(
        R.layout.actionbar_custom_view_done_discard, null);

// Show the custom ActionBar view and hide the normal Home icon and title.
DetailsHost.mActionBar.setDisplayOptions(
        ActionBar.DISPLAY_SHOW_CUSTOM,
        ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_SHOW_TITLE);
DetailsHost.mActionBar.setCustomView(customActionBarView, 
        new ActionBar.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

(根据罗马Nuriks code)。

(based on Roman Nuriks code).

我如何恢复初始布局?注:我用ActionBarSherlock

How do I restore the initial layout? Note: I use ActionBarSherlock

推荐答案

由于您只添加了一个自定义视图酒吧不删除标题应该是足以隐藏定制查看。您可以使用方法 setDisplayShowCustomEnabled()。只要致电:

Show/hide custom actionbar view

Since you only added a custom view to the bar without removing the title it should be sufficient to hide that custom View. You can use method setDisplayShowCustomEnabled(). Just call:

getActivity().getActionBar().setDisplayShowCustomEnabled(false);

和重新启用回家功能:

getActivity().getActionBar().setDisplayShowHomeEnabled(true);

(注意:在所有code示例使用 getSupportActionBar()而不是 getActionBar()如果您使用的是动作条compat的。另外, getActivity()仅从片段需要,可在活动指的是活动本身,在大多数情况下

(Note in all code examples use getSupportActionBar() instead of getActionBar() if you're using actionbar compat. Also the getActivity() is only needed from fragments, in activities refer to the activity itself, in most cases this)

然而,如果你创建自定义视图时也去掉标题,你就必须启用再也。

If however you also removed the title when creating your custom view you'll have to enable that again also.

getActivity().getActionBar().setDisplayShowTitleEnabled(true);

完全恢复

您也可以拨打setDisplayOptions()方法的选项的组合重新配置的动作条在一个调用。下面的例子中删除自定义视图,并显示标题。

Restore completely

You can also call the setDisplayOptions() method with a combination of options to reconfigure the actionbar in one call. The below example removes the custom view and shows the title.

getActivity().getActionBar().setDisplayOptions(
    ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);

请参阅<一href="http://developer.android.com/reference/android/support/v7/app/ActionBar.html#setDisplayOptions(int)"相对=nofollow> Android的API文档有关这些选项的详细信息。

See Android API docs for more details on these options.

这篇关于恢复默认动作条的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆