如何在ActionBar中显示自定义视图?

7

我正在尝试在操作栏中显示自定义视图。我正在使用SherlockActionBar。 以下是我的代码。自定义视图从未显示。我做错了什么?

View customNav = LayoutInflater.from(this).inflate(R.layout.my_layout, null);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setCustomView(customNav);
1个回答

15

您必须先启用自定义视图。

    getSupportActionBar().setDisplayShowCustomEnabled(true); // missing in your code
    getSupportActionBar().setCustomView(customNav);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接