showContextMenuForChild in listview adapter语言 - style of conte



我在安卓8.1上开发应用程序, 我有带有上下文菜单的列表视图的活动。列表项是由三个元素组成的组,其中一个元素是可单击的。因此,对于此元素,不调用上下文菜单。对于调用上下文菜单,我使用:

imageView.setOnLongClickListener(new View.OnLongClickListener()
{
@Override
public boolean onLongClick(View v) {
parent.showContextMenuForChild(v);
return true;
}
});

在适配器 getView(( 中。

但在这种情况下,上下文菜单样式是模态样式,但在所有应用程序样式中都是弹出样式的默认样式。如何在我的情况下将样式更改为弹出窗口。

PS:我认为这个showContextMenuForChild的问题,因为如果在活动中调用showContextMenuForChild,上下文菜单的样式也会更改为Modal-style。

panel.setOnTouchListener( new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// save the X,Y coordinates
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
lastTouchDownXY[0] = event.getX();
lastTouchDownXY[1] = event.getY();
}
// let the touch event pass on to whoever needs it
return false;
}

}(;

panel.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
float x = lastTouchDownXY[0];
float y = lastTouchDownXY[1];
parent.showContextMenuForChild(v,x ,y);
//parent.showContextMenu(x + v.getPivotX(),y);
}
return true;
}

}(;

第一个函数检测触摸坐标,第二个设置上下文菜单的位置!谢谢大家。

相关内容

最新更新