标签: contextmenu

我可以从自定义类(而不是活动类)中扩充上下文菜单吗?

我正在编写一个应用程序,其中我希望用我自己制作的对象填充网格视图。我的自定义对象的代码如下。我希望我的对象能够扩展上下文菜单。

我的问题是我似乎无法在 Activity 类之外使用 getMenuInflater() 方法。。。为了绕过这个限制,我将我的主要活动传递到该对象中。虽然这确实让我可以调用 getMenuInflater() 方法,但在运行代码时我仍然看不到菜单。

任何帮助表示赞赏!

我确实知道我可以直接从 Activity 类中扩展菜单。但是,如果可能的话,我想将所有这些功能保留在自定义对象中。

import java.io.File;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ImageView;

public class AnimalKind extends ImageView implements OnClickListener, OnLongClickListener{

    private int         m_imageId, m_soundId;
    private Context     m_ctx;
    private Activity    m_activity;


    public AnimalKind(Context ctx, int imageId, int soundId, Activity act) { …
Run Code Online (Sandbox Code Playgroud)

java android contextmenu

5
推荐指数
1
解决办法
604
查看次数

修订后的 Excel“单元格”上下文菜单在表格中不起作用

我在 Excel 中为右键单击上下文菜单创建了一个新项目。当我右键单击表格中的单元格时,它不会出现在右键单击上下文菜单中。否则确实会出现。我使用的代码(从网络复制)是:

Sub AddItemToContextMenu()
  Dim cmdNew As CommandBarButton
  Set cmdNew = CommandBars("cell").Controls.Add

  With cmdNew
    .Caption = "Copy Occurence Across"
    .OnAction = "CopyOccurrence"
    .BeginGroup = True
  End With
End Sub
Run Code Online (Sandbox Code Playgroud)

我可以做些什么来让我的新项目在单击表格中的单元格时出现吗?

excel vba contextmenu

5
推荐指数
1
解决办法
4373
查看次数

ContextMenuStrip 未正确调整大小

当我更改ToolStripLabel上下文菜单中的文本时,当我更改菜单项的文本时,上下文菜单不会按预期自动调整大小。
那么看起来像这样:

在此输入图像描述

如何使上下文菜单正确调整大小?
我可以更改真实菜单项的文本,但我认为这是一个肮脏的解决方案。


测试表格:( 使用鼠标左键,左侧和右侧)

using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1: Form
    {
        private ToolStripLabel menuLabel;

        private void CreateNewContextMenu()
        {
            ContextMenuStrip = new ContextMenuStrip();

            // label
            menuLabel = new ToolStripLabel("hello");
            menuLabel.ForeColor = Color.Blue;
            ContextMenuStrip.Items.Add(menuLabel);

            // items
            ContextMenuStrip.Items.Add("Test");
            ContextMenuStrip.Items.Add("Cut");
            ContextMenuStrip.Items.Add("&Copy");
            ContextMenuStrip.Items.Add("&Paste");
            ContextMenuStrip.Items.Add("&Delete");
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            CreateNewContextMenu();
            menuLabel.Text = "hello world hello world hello world";
            Point p = PointToScreen(Point.Empty);

            // left
            if (e.X < ClientSize.Width / 2)
                ContextMenuStrip.Show(p.X + 8, …
Run Code Online (Sandbox Code Playgroud)

c# contextmenu toolstrip winforms

5
推荐指数
1
解决办法
2189
查看次数

使用应用程序命令的 WPF 通知图标上下文菜单被禁用

我有一个 WPF PRISM 应用程序,其主窗口基于 ribbinwindow。当我右键单击图标托盘中的图标时,退出菜单被禁用。有人可以告诉我如何启用它并正确处理关闭事件。

我显示了主窗口的整个代码,但让我头疼的是通知图标的上下文菜单。我通过尝试用谷歌搜索解决此问题,找到了placementTarget commandtarget 绑定,但这似乎不起作用。
功能区按钮也以与上下文菜单相同的方式绑定,确实按预期工作。

在这种情况下,我更愿意保留命令绑定而不处理事件,因为我正在使用 MVVM。可以通过简单地调用一个事件并在该事件中调用 close 来处理关闭,而不会出现关注点分离问题,但我也将使用其他命令。所以请不要举办任何活动。

<ribbon:RibbonWindow x:Class="_2Focus.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ribbon="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon" 
    xmlns:prism="http://www.codeplex.com/prism"
    xmlns:tb="http://www.hardcodet.net/taskbar"
    Title="2Focus" Icon="/2Focus;component/favicon.ico"
    x:Name="Mainwindow"
    Height="500" Width="900">
<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition x:Name="RibbonRow" Height="Auto"/>
        <RowDefinition x:Name="ClientRow" Height="*"/>
    </Grid.RowDefinitions>
    <tb:TaskbarIcon IconSource="/2Focus;component/favicon.ico" ToolTipText="2 Focus" >
        <tb:TaskbarIcon.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Exit" Command="ApplicationCommands.Close" 
                          CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}">
                    <MenuItem.Icon>
                        <Image Source="Images/exit.png" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Second Menu Item" />
            </ContextMenu>
        </tb:TaskbarIcon.ContextMenu>
    </tb:TaskbarIcon>
    <ribbon:Ribbon x:Name="Ribbon" prism:RegionManager.RegionName="RibbonRegion" SelectionChanged="Ribbon_SelectionChanged" >
        <ribbon:Ribbon.QuickAccessToolBar>
            <ribbon:RibbonQuickAccessToolBar Name="ribbonQuickAccessToolBar" AllowDrop="True" />
        </ribbon:Ribbon.QuickAccessToolBar>
        <ribbon:Ribbon.ApplicationMenu>
            <ribbon:RibbonApplicationMenu SmallImageSource="/2Focus;component/favicon.ico"> …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf contextmenu notifyicon

5
推荐指数
0
解决办法
629
查看次数

当 OSx Mojave 中的 Finder 中未选择任何内容时,如何向右键单击上下文菜单添加选项?

我想知道是否可以修改右键单击 Finder 中任何特定内容时弹出的上下文菜单(如下右侧所示)

我可以轻松地将选项添加到右键单击某个项目(左侧)时弹出的上下文菜单...但是有没有办法将选项添加到右侧的菜单中?

例如,我可以在“新文件夹”下方添加自定义选项“新 Majig”吗?

上下文菜单比较

更多信息:

如果它有用,以下是我创建我想要使用的选项的方法:

  1. 我在Automator > Quick Action中创建了自定义选项,如下所示:

在 Automator 中创建服务

  1. 然后我将它们添加到系统偏好设置 > 键盘 > 快捷方式 > 服务中的上下文菜单中

将服务添加到上下文菜单

细节:

我在莫哈韦 10.14.2

macos applescript contextmenu automator macos-mojave

5
推荐指数
1
解决办法
3381
查看次数

仅在特定文件名(+扩展名)的上下文菜单中显示命令

所以基本上我只想在右键单击名为“example.cs”的文件时显示命令。由于我使用的是 Visual Studio 2019,我不能采用旧的BeforeQueryStatus方式。相反,使用ProvideUIContextRule我的 Package 类上的属性。目前看起来像这样:

    [ProvideUIContextRule(_uiContextSupportedFiles,
    name: "Supported Files",
    expression: "CSharp",
    termNames: new[] { "CSharp" },
    termValues: new[] { "HierSingleSelectionName:.cs$" })]
Run Code Online (Sandbox Code Playgroud)

对于文件本身的扩展名来说,这看起来完全不错。那么有什么办法可以限制example.cs呢?

顺便说一句,我正在使用本指南。

contextmenu visual-studio vsix visual-studio-extensions visual-studio-2019

5
推荐指数
1
解决办法
875
查看次数

是否有扩展 react-leaflet Map 组件以使用 Leaflet.contextmenu 的示例?

react-leaflet-context-menu 是leaflet.contextmenu 的react 版本。然而它使用原始的传单映射来实现反应中的插件而不是使用反应传单。

我在我的应用程序中采用了 react-leaflet,使用组件。我浏览了互联网,但没有多少示例来展示如何正确扩展 Map。

这是我的应用程序中的地图代码:

<LeafletMap
        ref={m => {this.leafletMap = m;}}
        center={this.state.center}
        zoom={this.state.zoom}
        maxZoom={this.state.maxZoom}
        preferCanvas={this.state.preferCanvas}
        contextmenu={this.state.contextmenu}
        contextmenuWidth={this.state.contextmenuWidth}
        contextmenuItems={this.state.contextmenuItems}>
        <TileLayer
          url={mapsource}
          />
        <MarkerClusterGroup showCoverageOnHover={false} zoomToBoundsOnClick={false} maxClusterRadius={30}>
          {CamMarkers}
        </MarkerClusterGroup>
        <ScaleControl imperial={false} metric={true}/>
</LeafletMap>
Run Code Online (Sandbox Code Playgroud)

我期望通过扩展 react-leaflet 的组件,它可以直接支持leaflet.contextmenu。道具 contextmenu、contextmenuWidth、contextmenuItems 将被输入到扩展组件,并在地图上右键单击时显示一些控件。

contextmenu reactjs react-leaflet

5
推荐指数
1
解决办法
654
查看次数

有什么方法可以覆盖 iOS 13 上下文菜单的(深色/浅色)用户界面样式?

我的应用程序支持 iOS 13 暗模式,并为用户提供匹配系统外观或强制应用程序始终使用暗模式或亮模式的选项,而不管系统设置如何。

该应用程序还允许在用户按下 时显示上下文菜单UILabel。但是,当使用UIContextMenuInteractionDelegate方法呈现上下文菜单时,我找不到任何方法来覆盖菜单的深色/浅色外观,也找不到UITargetedPreview在上下文菜单出现和消失时动画的视图外观。

例如,如果 iOS 外观设置为浅色模式并且用户在应用程序中选择强制深色模式的选项,则上下文菜单显示为浅色。我想覆盖该行为,使它们看起来很暗 - 有什么方法可以实现这一目标吗?我似乎找不到overrideUserInterfaceStyle与上下文菜单相关的属性。

我使用的代码如下供参考。

// Setup code

if #available(iOS 13.0, *) {
    self.textLabel.addInteraction(UIContextMenuInteraction(delegate: self))
}

// UIContextMenuInteractionDelegate

@available(iOS 13.0, *)
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
    let text = self.text
    return UIContextMenuConfiguration(identifier: nil, previewProvider: { return TextViewController(text: text) }) { [weak self] _ in
        return self?.contextMenu(for: text)
    }
}

@available(iOS 13.0, *)
private func contextMenu(for text: String) -> UIMenu { …
Run Code Online (Sandbox Code Playgroud)

contextmenu ios swift ios13

5
推荐指数
1
解决办法
1554
查看次数

WKWebView 不会显示图像的自定义 UIContextMenuConfiguration

I\xe2\x80\x99m 尝试在 iOS 13 上为我的 WKWebView 创建自定义上下文菜单。I\xe2\x80\x99m 能够覆盖普通链接的默认上下文菜单,但是,当我点击并按住图像时,默认上下文菜单显示。

\n

这是我的代码:

\n
-(void) webView:(WKWebView *)webView \ncontextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo \ncompletionHandler:(void (^)(UIContextMenuConfiguration *configuration))completionHandler {\n    NSURL *url = elementInfo.linkURL;\n    __block BOOL isURLImage;\n    __block UIImage *image;\n    if (url != nil) {\n        UIAction *openURL = [UIAction actionWithTitle:@"Open URL" image:nil identifier:nil handler:^(UIAction *action) {\n            [self.webView loadRequest:[NSURLRequest requestWithURL:url]];\n        }];\n        UIAction *openNewTab = [UIAction actionWithTitle:@"Open in new tab" image:nil identifier:nil handler:^(UIAction *action) {\n            [self createNewTab:url];\n        }];\n        \n        dispatch_async(dispatch_queue_create("getImage", NULL), ^(void) {\n            NSData *data = [NSData dataWithContentsOfURL:url];\n            image = [UIImage imageWithData:data];\n …
Run Code Online (Sandbox Code Playgroud)

contextmenu objective-c ios wkwebview uicontextmenuconfiguration

5
推荐指数
0
解决办法
1558
查看次数

即使指定 contentShape 后,ContextMenu 仍使用不正确的cornerRadius

struct CardView: View {
    private var name: String = "Random Name"
    private var color: Color = Color.red
    
    private var CardContent: some View {
        HStack(alignment: .top) {
            Text(name)
                .font(.system(size: 16, weight: .medium, design: .rounded))
                .frame(width: 110, height: 80, alignment: .top)
        }
        .padding(.top, 20)
        .frame(width: 200, height: 190, alignment: .top)
        .background(color)
        .clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
    }
    
    var body: some View {
        CardContent
            .contentShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
            .contextMenu {
                Button(action:{}){
                    HStack {
                        Image(systemName: "trash")
                            .foregroundColor(Color.red)
                        Text("Delete")
                    }
                }
        }
        .shadow(color: color.opacity(0.5), radius: 10, …
Run Code Online (Sandbox Code Playgroud)

contextmenu ios swift swiftui

5
推荐指数
1
解决办法
609
查看次数