How to show popup window over dialog Android - android

I need help. I want to show a popup window over dialog.
On API 23 i did it. But on API >23 i can do this. See images.
API > 23
API < 23
Thanks for help.

#TuNguyen Not sure if you're still looking for an answer but for people who're still facing this: I resolved it using the (WindowLayoutType) for the popupWindow. Adding this works:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
popupWindow.windowLayoutType = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG
//Refer to the android's doc I attached above for the complete list of WindowLayouts
}
//I am using Kotlin

Related

Show PopupWindow above all window for target android 26

I want to show PopupWindow above all window (example: another popupwindow, dialog, another activity screen) without request SYSTEM_ALERT_WINDOW so I use WindowManager.LayoutParams.TYPE_TOAST
public void showSimplePopupWindow() {
final View popupView = layoutInflater.inflate(R.layout.popup_layout_2, null);
final PopupWindow popupWindow = new PopupWindow(popupView);
...config popup window...
PopupWindowCompat.setWindowLayoutType(popupWindow, WindowManager.LayoutParams.TYPE_TOAST);
popupWindow.showAsDropDown(findViewById(R.id.button_show_popup_window));
}
It working well in all android version if I set targetSdkVersion < 26 .
Currently, If I keep the code above and update the target targetSdkVersion to 26 then it will crash with device api 25-26 with exception android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W#859d91f is not valid; is your activity running?
I see that TYPE_TOAST is deprecated in sdk 26 and they suggest to use TYPE_APPLICATION_OVERLAY. However, when I use TYPE_APPLICATION_OVERLAY, AndroidStudio show TYPE_APPLICATION_OVERLAY required api 26. Therefore, TYPE_APPLICATION_OVERLAY only work well with device api 26, for device api < 26, it will crash ( even I have enabled Display/Draw over other app permission)
Is there any alternative way to make TYPE_TOAST work with target api 26? Any help or suggestion would be great appreciated.
There appears to be a bug with API 25. The bug is that if you change the target API to be 26, API 25 devices will no longer be able to use the TYPE_TOAST parameter, even though it is allowable in API 25.
The only way to fix this behavior is to have the user enable overlay permissions in Settings for your app. API 25 and 26 overlays will then function as expected.
Since:
TYPE_APPLICATION_OVERLAY (introduced in Api level 26) is a constant value 2038 (0x000007f6)
TYPE_TOAST (since Api level 1!) is a constant value 2005 (0x000007d5)
one option would be to check the System Version at Runtime and, depending on its value, using the right constant.

How do I make make my notification use default application colours?

I am following this tutorial on notifications, however, my notification is greyed out.
I know there's remote views to style it, but this developers guide does not use it.
Here is an example of how my notification looks
In your builder, use .setColor()
it requires a minimum api
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setColor(Color.BLUE);
}

Android : setOverlapAnchor before API 23

My activity has a popup window defined like this :
this.navigationMenuPopupWindow = new PopupWindow(View.inflate(this, R.layout.popup_navigation, null), ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
this.navigationMenuPopupWindow.setWidth((int) this.getResources().getDimension(R.dimen.navigation_popup_width));
this.navigationMenuPopupWindow.setBackgroundDrawable(this.getDrawable(R.drawable.main_bg_navigation_menu));
this.navigationMenuPopupWindow.setElevation(43);
this.navigationMenuPopupWindow.setFocusable(true);
this.navigationMenuPopupWindow.setOutsideTouchable(true);
I would like to position the popup under the anchor. So I naturally tried to add this line :
this.navigationMenuPopupWindow.setOverlapAnchor(false);
Unfortunately, it requires the API 23.
How can I achieve the same result but that it is compatible with the API 21?
I think I can resolve this by modifying my app style, but I don't know exactly how. By the way, this can affect all the PopupWindows of the app, it's not a problem I only have that one. Thank you for your help!
You need to use PopupWindowCompat.
PopupWindowCompat.setOverlapAnchor(this.navigationMenuPopupWindow,true);
Be aware that the PopupWindowCompat.setOverlapAnchor has no implementation before API 21.

Android LayoutTransition

I want to use the LayoutTransition class that it can achieve animation.But Eclipse tell me Call requires API level 11 (current min is 7). And I just want to call this API in Android2.1+. So, Here What way can be deal with it(such as the Open Sources library)?
Thank you very much for your answer.
This error comes from Android Lint. You can suppress it by adding an
#SuppressLint("NewApi"). Then in the body of the method using LayoutTransition you can add the following code:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
//use LayoutTransition in your code
} else {
//on Android 7-11, don't use LayoutTransition
}

Hide time in Android notification without using custom layout

In the bottom right corner of a standard Android notification is time (eg 12:00). Can I hide it without using custom notification layout?
For API level 17 and onward, the above accepted answer by Erwan is correct.
For historical purposes, the answer below remains
It is possible to do that.
Try setting when to 0.
For the few notifications that don't do that, it looks like thats what they do.
Here's the general API reference.
Here's a link to the ADB notification and search for private void updateAdbNotification()...
From API Level 17 onwards, you can use setShowWhen(false)
public Notification.Builder setShowWhen (boolean show)
Added in API level 17 Control whether the timestamp set with setWhen
is shown in the content view.
http://developer.android.com/reference/android/app/Notification.Builder.html#setShowWhen(boolean)
For API level 17 and onward,
mBuilder.setShowWhen(boolen);
1.Use Hide Notification Time
mBuilder.setShowWhen(false);
2.Use Show Notification Time
mBuilder.setShowWhen(true);

Categories

Resources