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

Pet*_* D. 7 android actionbarsherlock android-actionbar

我试图在操作栏中显示自定义视图.我正在使用SherlockActionBar.这是我的代码.自定义视图永远不会显示.我究竟做错了什么?

View customNav = LayoutInflater.from(this).inflate(R.layout.my_layout, null);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setCustomView(customNav);
Run Code Online (Sandbox Code Playgroud)

zna*_*nat 15

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

    getSupportActionBar().setDisplayShowCustomEnabled(true); // missing in your code
    getSupportActionBar().setCustomView(customNav);
Run Code Online (Sandbox Code Playgroud)