did you notice any UI issues with Android OS 11(API 30).
I have a full screen transparent dialog with a progressbar at center, it is working till Android 10, don't know its showing a black dark background in Android 11. Please share if you guys have any thoughts on this issue.
This is how I am setting dialog background transparent:
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Well, setBackgroundDrawable() is deprecated now that's probably why you are getting this issue. An alternative could be setBackgroundResource(R.drawable.your_drawable) where you can replace the drawable with your color.
Struggling with same issue lead me to this solution;
Window window = dialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.argb(58, 0, 0, 0)));
dialog.requestWindowFeature(1);
dialog.setContentView(R.layout.dialog_layout);//Set contentView after setting background drawable
dialog.show();
Simple, setting the contentView after setting background drawable solved the issue. There might some other approaches like setting background as resource. This is what fit for me.
Without further details I can only make a guess on the solution. But I believe this is an issue where LayoutParams are being replaced. Instead I would suggest modifying the LayoutParams a view/window already have.
Get the layout params:
WindowManager.LayoutParams params = window.attributes;
Modify attributes as you like, e.g. params.width = WRAP_CONTENT And then set the modified layout params:
window.attributes = params
I suggest this solution to all LayoutParams, it usually give the best solution to more android versions. And less attributes has to be set.
Related
First, I am adding Gridview and second i add imageview in the gridview, but the layout can't show up the image。
Does anyone know what the problem could be?
Thank you very much!!
Simply change the height and width attributes :)
Don't drag, use xml text editor instead. And as mentioned above use height and width appropriate.
Android Studio shows you a warning, next to the ImageView (yellow warning icon). If you hover over this, it will tell you what the problem is. (most likely missing height and width)
I would like to solve the problem I've got. I made a dialog above a activity of android, but I would like to make the background black(opaque). All the guide shows only how to make it transparent. How can I make it opaque?
Yes, it is. You can control it.
After creating dialog:
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount=0.0f; // Dim level. 0.0 - no dim, 1.0 - completely opaque
dialog.getWindow().setAttributes(lp);
Upd: you can even add blur behind the dialog:
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Hello If i understand your question correctly then you can do it by below code :
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
mDialog.getWindow().setBackgroundDrawable(d);
Use this line :
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(0xff000000));
hope it helps :)
In one of my project I used PopupWindow. My problem is while viewing popupwindow the design seems to be uncomfortable to work. So I want to dim or blur my activity background. I searched a lot, but most of the answers seems only for Dialog not for PopupWindow. Is it possible in android to dim our activity background while viewing PopupWindaow.
I solved this problem by setting the background to the layout of the pop-up window with the following.
android:background="#80FFFFFF"
Thnaks..And it works as expected.
you can simply use this :
ColorDrawable dw = new ColorDrawable(0xb0000000);
dialog.getWindow().setBackgroundDrawable(dw);
There is always a work around. Before showing your PopupWindow use another PopupWindow which has nothing but a dark translucent tint. Also when dismissing dismiss both pop up windows in the reverse sequence.
For code see this
Yes, it is possible, try android:theme="#android:style/Theme.Translucent" , it will make your activity transparent.
Try this
Window window = popUpView.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.CENTER_VERTICAL;
wlp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
wlp.dimAmount = (float) 1.0;
window.setAttributes(wlp);
I use an AsyncTask with a ProgressDialog in it.
This automatically causes a background dim of about 40%. I want to turn this dim off (0% dim), but what I tried, didn't work:
myLoadingDialog = new ProgressDialog(MainActivity.this.getApplicationContext());
myLoadingDialog.setMessage("Loading...");
myLoadingDialog.setIndeterminate(true);
myLoadingDialog.setCancelable(false);
WindowManager.LayoutParams lp = myLoadingDialog.getWindow().getAttributes();
lp.dimAmount = 0.0f;
myLoadingDialog.show();
The problem with that dim was, that I had to terminate my Tablet's SystemUI-Process to achieve a Kiosk mode (with no System-Bar) and the ProgressDialog dims everything but the area where the System-Bar was, so I have a bright border at the bottom of the screen.
If there is a way to get a complete fullscreen-dim, I would be also happy.
Thanks for any help
use
myLoadingDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
you can add this theme to solve this problem also
<item name="android:backgroundDimEnabled">false</item>
You can also change the relative amount of dimming with the following:
window?.setDimAmount(0.2f)
This is set in onCreate of your dialog class.
I have a ImageView as background of appWidgets layout. So I want to change both background resource (nine patch image) and background transparency. I tried as below:
rv.setInt(R.id.widget_background, "setBackgroundColor", 0);
rv.setInt(R.id.widget_background, "setBackgroundResource", nBackgroundId); // set background_id
rv.setInt(R.id.widget_background, "setAlpha", nTransparency); // set transparent
But nothing is happened, could anybody tell me the solution to solve my problem?
Which version is your android sdk? It requires Froyo or greater