I've searched lots of sites but they are all out-of-date. How to create full-screen floating context menu in Android 8.0?
As you can see here, Google gives us instructions how to do it in its guides but I guess they are out-of-date as well. Why? Here's an example:
This is how it looks like on API 23 (source, his github codes say it's API 23 = Android 6.0)
And this is how it looks like on API 26 (Android 8.0):
There must be some changes between these APIs but I can't really get an answer.
Any solutions would be appreciated.
It's actually a version specific behaivor.
Workaround for the project that you linked:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
registerForContextMenu(button);
button.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
button.showContextMenu();
return true;
}
});
}
if read the documentation about performLongClick() of the View class:
/**
* Calls this view's OnLongClickListener, if it is defined. Invokes the
* context menu if the OnLongClickListener did not consume the event,
* anchoring it to an (x,y) coordinate.
*
* @param x x coordinate of the anchoring touch event, or {@link Float#NaN}
* to disable anchoring
* @param y y coordinate of the anchoring touch event, or {@link Float#NaN}
* to disable anchoring
* @return {@code true} if one of the above receivers consumed the event,
* {@code false} otherwise
*/
public boolean performLongClick(float x, float y)
so it's a standard realisation of showing context menu (if you register listener context menu on view, it will processed with coordinates). So to avoid showing menu with coordinates, just show directly on long click of the view by showContextMenu()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With