- Nでは長押しした位置にContextMenuが出るがどうやっているか
View#performLongClick(int,int)とView#showContextMenu(int,int)が追加されているView#performLongClickInternalで指の位置があるかによってshowContextMenu(int,int)とshowContextMenu()を呼び分け- NではDarkThemeにするとPopupWindowが黒背景になるが、どうにかならんのか
- M以前はDialogだったのでテーマを書き換えられた。NはPopupかつ
com.android.internal.R.attr.contextPopupMenuStyleを使っているのできびしそう?
View#performLongClick(int,int)View#performLongClickInternal(int,int)View#showContextMenu(int,int)ViewGroup#showContextMenuForChild(View,float,float)AbsListView#showContextMenuForChild(View,float,float)AbsListView#showContextMenuForChildInternal(View,float,float,boolean)ViewGroup#showContextMenuForChild(View,float,float)mParent.showContextMenuForChild(View,float,float)でどこまで遡るかと思ったらDecorView#showContextMenuForChild(View,float,float)DecorView#showContextMenuForChildInternal(View,float,float)ContextMenuBuilder#showPopup(Context,View,float,float)MenuPopupHelper#show(int,int)MenuPopupHelper#tryShow(int,int)MenuPopupHelper#showPopup(int,int,boolean,boolean)MenuPopup#show()- 🎉
View#performLongClick(int,int)の実装が荒い- http://tools.oesf.biz/android-7.0.0_r1.0/xref/frameworks/base/core/java/android/view/View.java#5659
public boolean performLongClick(float x, float y) {
mLongClickX = x;
mLongClickY = y;
final boolean handled = performLongClick();
mLongClickX = Float.NaN;
mLongClickY = Float.NaN;
return handled;
}
DecorView#showContextMenuForChildInternal(View,float,float)- 指の位置があればDialog,なければPopup
- http://tools.oesf.biz/android-7.0.0_r1.0/xref/frameworks/base/core/java/com/android/internal/policy/DecorView.java#787
if (isPopup) {
helper = mWindow.mContextMenu.showPopup(getContext(), originalView, x, y);
} else {
helper = mWindow.mContextMenu.showDialog(originalView, originalView.getWindowToken());
}
- MenuPopupの表示のところで謎の数字出てきたな?と思ったらこんなことが書いてあった
- http://tools.oesf.biz/android-7.0.0_r1.0/xref/frameworks/base/core/java/com/android/internal/view/menu/MenuPopupHelper.java#265
PopupWindow#setEpicenterBounds、使っていこう
// Set the transition epicenter to be roughly finger (or mouse
// cursor) sized and centered around the offset position. This
// will give the appearance that the window is emerging from
// the touch point.
- v7にも
MenuPopupHelperがあるので、M以前でもタップ位置からContextMenu出せるかも? - 調べてみたらActionMenu用のようだ
- ContextMenuで流用するのもそんなにつらくないかも