添加按钮到Android动作栏

sar*_*nan 6 android android-actionbar

如何使用文本制作按钮,操作栏中的图像如下所示.

是否可以使用Inbuilt android按钮或图像按钮在操作栏中执行如下操作.

我正在使用appcompat来使用操作栏.

在此输入图像描述

iva*_*arz 12

是的,如果需要,您可以为自定义操作栏充气.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LayoutInflater inflater = (LayoutInflater) getActionBar()
            .getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    View customActionBarView = inflater.inflate(R.layout.actionbar_custom, null);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(
            ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
                    | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView,
            new ActionBar.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));

    setContentView(R.layout.activity_main);
}
Run Code Online (Sandbox Code Playgroud)

actionbar_custom.xml将是您的布局资源,通常是一个LinearLayout,包含您想要的任何组件.


eli*_*rks 3

你是说行动项目吗?http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems

您需要创建一个菜单布局,如上面提到的指南所述。

Android 的默认图标集可以在这里找到:http ://developer.android.com/design/downloads/index.html