Snackbar crawls behind the top panel - java

I'm trying to place a snackbar at the top of the screen, but it's crawling behind the top bar. Why is this and how can I fix it
val snackBar = Snackbar.make(binding.videoPlayerBaseContainer, "test", Snackbar.LENGTH_SHORT)
val view = snackBar.view
val params = view.layoutParams as FrameLayout.LayoutParams
params.gravity = Gravity.TOP
view.layoutParams = params
snackBar.animationMode = BaseTransientBottomBar.ANIMATION_MODE_FADE
snackBar.show()

Related

How to show the keyboard for edittext in overlay?

I have an overlay and a text field in it. But when I want to enter text in the field, the virtual keyboard is not displayed.
I have tried all the flags (FLAG_LOCAL_FOCUS_MODE, FLAG_ALT_FOCUSABLE_IM, FLAG_NOT_FOCUSABLE), but it did not bring any result.
Here is my code:
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
width - 100,
height - 100,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
//WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
//WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.RIGHT;
params.x = 50;
params.y = 50;
ConstraintLayout rootView = (ConstraintLayout) LayoutInflater.from(this).inflate(R.layout.overlay_layout, null);
windowManager.addView(rootView, params);
How to fix it?

Kotlin, Inflated EditText, when keyboard shows, view is crumbled

when keyboard is up, inflated view show weird.
what may be the problem ?
val inflater = it.context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
val menuPopup = inflater!!.inflate(R.layout.popup_search_new_cosmetics,null)
val popup = PopupWindow(menuPopup, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT, true)
popup.showAtLocation(menuPopup, Gravity.CENTER,0,0)
val imgClose = menuPopup.findViewById<ImageView>(R.id.imageClose)
menuPopup.findViewById<ImageView>(R.id.imageClose)
enter code here

Kotlin - EditText in Inflated View keyboard show on back with black opacity

I inflated popup view with below code
but the problem is keyboard is shown backof popup
val inflater = it.context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
val menuPopup = inflater!!.inflate(R.layout.popup_search_new_cosmetics,null)
val popup = PopupWindow(menuPopup, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT, false)
popup.showAtLocation(menuPopup, Gravity.CENTER,0,0)
val imgClose = menuPopup.findViewById<ImageView>(R.id.imageClose)
menuPopup.findViewById<ImageView>(R.id.imageClose)
recycler = menuPopup.findViewById(R.id.editProductPage)
showKeyboard(menuPopup.findViewById(R.id.editTextSearch),this)
private fun showKeyboard(mEtSearch: EditText, context: Context) {
mEtSearch.requestFocus()
val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
}
I suggest to use Alert dialog...
Use this code. Your problem will be solved
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

How can I add a copy of my SupportMapFragment to my WindowManager to show it as a screen overlay?

I have an Android app that uses a screen overlay to place buttons on top of Pokemon Go. The buttons call methods to draw polygons on the map in the background. I have the buttons working how I want them to, but what I really want is to create an overlay onto of Pokemon go that shows my map so the user doesn't have to switch back and forth. (I just uploaded a version with the working buttons if you want to see that: https://play.google.com/store/apps/details?id=kavorka.venn_tracker).
I cant seem to get a copy of my SupportMapFragment into a view in my overlay, does anyone know a way to get this to work?
I am using a MapWrapperLayout so I can have a custom map info window with buttons (I don't know if there is a better way).
Here is the code that is called when I start the overlay:
Binder binder = new Binder();
WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.LEFT | Gravity.TOP;
params.width = 150;//mButtonCircleGreen.getLayoutParams().width;
params.height = 150;//mButtonCircleGreen.getLayoutParams().height;
params.token = binder;
WindowManager.LayoutParams greenParams = new WindowManager.LayoutParams();
WindowManager.LayoutParams redParams = new WindowManager.LayoutParams();
greenParams.copyFrom(params);
redParams.copyFrom(params);
greenParams.x = mSharedPref.getInt("overlay_green_x", (int) mButtonCircleGreen.getX());
greenParams.y = mSharedPref.getInt("overlay_green_y", (int) mButtonCircleGreen.getY());
redParams.x = mSharedPref.getInt("overlay_red_x", (int) mButtonCircleRed.getX());
redParams.y = mSharedPref.getInt("overlay_red_y", (int) mButtonCircleRed.getY());
topLeftView = new View(this);
WindowManager.LayoutParams topLeftParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT);
topLeftParams.gravity = Gravity.LEFT | Gravity.TOP;
topLeftParams.x = 0;
topLeftParams.y = 0;
topLeftParams.width = 0;
topLeftParams.height = 0;
topLeftParams.token = binder;
WindowManager.LayoutParams mapParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
mapParams.gravity = Gravity.CENTER | Gravity.CENTER;
mapParams.x = 0;
mapParams.y = 0;
mapParams.width = 1000;
mapParams.height = 1000;
mapParams.token = binder;
wm.addView(topLeftView, topLeftParams);
wm.addView(mMapView, mapParams);
wm.addView(mOverlayedButtonGreen, greenParams);
wm.addView(mOverlayedButtonRed, redParams);
Here is where I get my map:
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this);
mMapView = new MapView(this);
mMapView.getMapAsync(this);
// Window manager for overlay
wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Any ideas would be greatly appreciated :)

WindowManager - drawing on top of the navigation bar (buttons) Android

Good afternoon. I have a service in which the object is created and WindowManager View - is assigned parameter background (mView.setBackgroundColor(color). The fact is that now I have View drawn only over the main desktop screen and status bar, and navigation bar is not affected. How do I do to View draws and on top of the navigation bar (buttons) in the Android? At the moment:
#Override
public void onCreate() {
super.onCreate();
mView = new LinearLayout(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
0 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
}
Result:
enter image description here
That is all I have to paint in red, relatively speaking, including a navigation bar. Thank you.
int value_below_screen=100;
params.y=-value_below_screen;
this will offset the screen below by "value_below_screen"

Categories