0

我有一个自定义对话框,我想在其中添加一些带有 android 日历之类的图标的操作项。

带有操作项对话框的 android 日历

这是为我的活动提供主题的清单代码:

    <activity
        android:name=".FileChooser"
        android:label="FileChooser"
        android:theme="@android:style/Theme.DeviceDefault.Dialog"  tools:ignore="NewApi">
    </activity>

在 FileChooser.java 中:

     public boolean onCreateOptionsMenu(Menu menu) 
 {
        MenuItem camramnu= menu.add(0,0,0,"Take a picture");
        {
            camramnu.setIcon(R.drawable.camera);
            camramnu.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        }
        return true;
 }

它从不显示图标!

我该怎么做 ?

4

2 回答 2

1

我看到了问题 - 您有一个选项菜单,但是从您包含的图像中,已经有一个看起来像上下文操作栏菜单正在运行的东西,带有“完成”和“取消”

也许你需要设置你的菜单选项

http://developer.android.com/guide/topics/ui/menus.html#CAB

在这种情况下,

private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {

// Called when the action mode is created; startActionMode() was called
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    // Inflate a menu resource providing context menu items
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.context_menu, menu);
    return true;
}

// Called each time the action mode is shown. Always called after onCreateActionMode, but
// may be called multiple times if the mode is invalidated.
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    return false; // Return false if nothing is done
}

// Called when the user selects a contextual menu item
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_share:
            shareCurrentItem();
            mode.finish(); // Action picked, so close the CAB
            return true;
        default:
            return false;
    }
}

// Called when the user exits the action mode
@Override
public void onDestroyActionMode(ActionMode mode) {
    mActionMode = null;
}

};

于 2013-04-06T21:49:49.503 回答
0

您的菜单在片段中吗?在片段中,您必须使用 setHasOptionsMenu(true);

于 2013-04-05T19:16:26.750 回答