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

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

Related

Remove container padding for BottomSheet Android

Have a space under the BottomSheet, I think it's the navigation bar what I hide before. I want remove this space. In Layout Inspector I noticed the R.id.container (FrameLayout) of BottomSheet have padding 48dp, bu idk what is it. Tried remove it, but it doesn't work. Screenshot
Layout Inspector
private void showAndHandleBottomSheetDialog() {
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setContentView(R.layout.bottom_sheet_dialog_layout);
bottomSheetDialog.setCanceledOnTouchOutside(false);
FrameLayout bottomSheet = (FrameLayout) bottomSheetDialog.findViewById(R.id.design_bottom_sheet);
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
RadioGroup radioGroupTip = bottomSheetDialog.findViewById(R.id.tip_list_custom);
ImageView buttonClose = bottomSheetDialog.findViewById(R.id.button_close);
ArrayList<TipItem> tipItemList = new ArrayList<TipItem>(Arrays.asList(TipItem.values()));
if (checkedButtonID != -1) {
radioGroupTip.check(checkedButtonID);
}
bottomSheetDialog.show();
buttonClose.setOnClickListener(view -> {
checkedButtonID = radioGroupTip.getCheckedRadioButtonId();
bottomSheetDialog.dismiss();
});}
The below approach will hide the systembars, if your problem's cause is the navigationbar then it should solve it.
private void showAndHandleBottomSheetDialog() {
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
// here you need to inflate your view and hide system bars, then set it.
// The added code for kotlin, kindly convert it to java
val bottomSheetView = LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_dialog_layout,
view?.findViewById(R.id.IdOfYourDialogParent)
)
bottomSheetView.systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
bottomSheetDialog.setContentView(bottomSheetView);
Maybe you can check parent of container has padding too.
I can't see where is the problem from code or picture.
The source code for BottomSheetDialog

Snackbar crawls behind the top panel

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()

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 to do android dialog flip animation

I have an android dialog with button "feedback"
I want the user to write his input.
how can I create flip animation to flip this dialog a "enter feedback" dialog ?
I have tried:
private void flipCard() {
View rootLayout = (View) mDialog.findViewById(R.id.main_activity_root);
View cardFace = (View) mDialog
.findViewById(R.id.main_activity_card_face);
View cardBack = (View) mDialog
.findViewById(R.id.main_activity_card_back);
FlipAnimation flipAnimation = new FlipAnimation(cardFace, cardBack);
if (cardFace.getVisibility() == View.GONE) {
flipAnimation.reverse();
}
rootLayout.startAnimation(flipAnimation);
}

Full Screen AlertDialog changes the layout color

I'm using the code from another answer here:
AlertDialog.Builder adb = new AlertDialog.Builder(this);
Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.FILL_PARENT;
lp.height = WindowManager.LayoutParams.FILL_PARENT;
d.show();
d.getWindow().setAttributes(lp);
I really find it usefl to make an alertDialog full screen, but the colors end up being a black background with white text, instead of a white background with black text. I have no idea how this code could be changing the color. Could anyone provide some info?
In the line:
Dialog d = adb.setView(new View(this)).create();
you ceate a new View which defaults to black background.
Then you use this view attributes everywhere:
lp.copyFrom(d.getWindow().getAttributes());
d.getWindow().setAttributes(lp);
Solution:
After creating the new view, set the background:
View view = new View(this);
view.setBackgroundColor(...);
Dialog d = adb.setView(view).create();
Regards.

Categories