网页 综合 更新时间 2026-11-13 21:53:27

Menu | Electron

自动蜘蛛 www.electronjs.org 正文约 3692 字
Create application menus and context menus.
The presentation of menus varies depending on the operating system:
[!TIP] See also: A detailed guide about how to implement menus in your application.
[!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.
La clase Menu tiene los siguientes métodos estáticos:
Establece menu como el menú de la aplicación en macOS. En Windows y Linux el menu será establecido como el menú superior de la ventana.
On Linux, the menu bar uses GTK theme colors when GTK is available. If GTK cannot initialize, it uses Chromium's built-in light or dark menu colors, following nativeTheme.shouldUseDarkColors.
Además en Windows y Linux, puedes usar un & en el nombre del ítem de nivel superior para indicar que letra debe obtener un acelerador generado. Por ejemplo, usando &File para el menú resultaría en un acelerador generado Alt-F que abre el menú asociado. El carácter indicado en la etiqueta del botón entonces aparecerá subrayado, y el carácter & no se mostrará en la etiqueta del botón.
In order to escape the & character in an item name, add a preceding &. Por ejemplo, &&Archivo abrirá &Archivo en la etiqueta del botón.
Passing null will suppress the default menu. On Windows and Linux, this has the additional effect of removing the menu bar from the window.
[!NOTE] The default menu will be created automatically if the app does not set one. It contains standard items such as File, Edit, View, and Window.
Devuelve Menu | null - El menú de aplicación, si se creó, o null en caso contrario.
[!NOTE] The returned Menu instance doesn't support dynamic addition or removal of menu items. Instance properties can still be dynamically modified.
Sets the colors used to highlight the hovered or keyboard-focused item in every menu the app shows, including context menus and the menu bar's dropdowns. Light and dark colors are set separately, and any color left unset keeps the default for that mode. Each call replaces the colors set by any previous call. Passing null restores the defaults.
Menus opened after the call use the new colors. The colors are not applied while Windows high contrast mode or forced colors are active, so the user's system colors take priority.
This method has no effect on macOS and Linux.
Envía la action al primer respondedor de la aplicación. Esto es usado para emular los comportamientos del menú macOS por defecto. Usually you would use the role property of a MenuItem.
See the macOS Cocoa Event Handling Guide for more information on macOS' native actions.
Generally, the template is an array of options for constructing a MenuItem. The usage can be referenced above.
Usted puede además adjuntar otros campos al elemento del template y se convierten en propiedades de los items del menú construido.
El objetomenu tiene los siguientes métodos de instancia:
Pops up this menu as a context menu in the BaseWindow.
[!TIP] For more details, see the Context Menu guide.
Closes the context menu in the window.
Anexa el menuItem al menú.
Returns MenuItem | null - the item with the specified id
Inserta el menuItem en la posición pos del menú.
Objetos creados con new Menu o retornados por Menu.buildFromTemplate emiten los siguientes eventos:
[!NOTE] Some events are only available on specific operating systems and are labeled as such.
Emitido cuando se llama a menu.popup().
Se emite cuando una ventana emergente se cierra manualmente o con menu.closePopup().
Los objetos menu también tienen las siguientes propiedades:
A MenuItem[] array containing the menu's items.
Each Menu consists of multiple MenuItem instances and each MenuItem can nest a Menu into its submenu property.
访问原文 返回搜索 https://www.electronjs.org/es/docs/latest/api/menu
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。