为上下文操作栏设置标题

Ami*_*ant 23 android android-actionbar

我想为上下文操作栏设置标题(如下图所示). 在此输入图像描述

我尝试过以下方法:

getActionBar().setTitle("Title for cab");
Run Code Online (Sandbox Code Playgroud)

但标题没有出现.

Ami*_*ant 20

我设法通过调用ActionMode的setTitle方法来设置标题.

mActionMode.setTitle("Title for cab");
Run Code Online (Sandbox Code Playgroud)


Bah*_*any 5

这个答案对我有用

    @Override
    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

        mode.setTitle(yourTitlehere);
        return false; // Return false if nothing is done
    }
Run Code Online (Sandbox Code Playgroud)