Android - AlertDialog won't show BitmapDrawable - android

In my app, I'm downloading a small Facebook profile picture and show it in an AlertDialog (as BitmapDrawable) along with the user first and last name.
Now, my problem is that on some devices the BitmapDrawable is shown in the AlertDialog (Android ~4.0) and on some it isn't (5.0 and above), but in all the devices the BitmapDrawable contains the right bitmap and I'm able to load that BitmapDrawable to an ImageView for example.
((ImageView)findViewById(R.id.imageView3)).setImageDrawable(bitmapDrawable); //Shown in the ImageView on all devices
AlertDialog ad = new AlertDialog.Builder(MainActivity.this)
.setTitle("From: " + name + " " + lastName)
.setMessage(theStr)
.setNeutralButton(theStr2, new myClick(marker, thePack))
.setIcon(bitmapDrawable) //Not shown in the AlertDialog on all devices
.show();
Any idea?
UPDATE: Even in the debugger I can see the icon set in the AlertDialog and the debugger also allow me to view the bitmap of it and it's shown perfectly. It's just won't show up in the dialog and I don't know why.

Try setting a drawable from the resource just to see if that works.
If I'm not wrong try changing the default app theme (It's weird but for me it worked in some special cases).
Also I've found this bug report while searching,
https://code.google.com/p/android/issues/detail?id=92929

Related

AlertDialog displays briefly and disappears

I have an android app written with Xamarin which needs to notify from a class that does not have good access to an activity or context, so I am using a System Alert dialog to display the message.
In Android 4.4, the pop-up appears and the user must tap the OK button to clear it. The rest of the screen is dim and the user cannot interact with any other UI elements until the pop-up is cleared. This is the desired behavior.
In Android 5.0 (tested on a Galaxy S6 and a tablet), the pop-up will appear for about one second and then disappear without requiring any interaction whatsoever. I have done a number of Google and SO searches to no avail.
private static void ShowSystemAlert(Context context, string message)
{
var dialog = new AlertDialog.Builder(context, Android.Resource.Style.ThemeHoloLightDialog)
.SetNeutralButton("OK", (alertSender, args) => {})
.SetMessage(message)
.Create();
dialog.SetCanceledOnTouchOutside(false);
dialog.Window.SetType(WindowManagerTypes.SystemAlert);
dialog.Show();
dialog.Window.DecorView.SetBackgroundResource(Android.Resource.Color.Transparent); //remove strange small border around dialog
}
How can I get the pop-up to work like it does in Android 4.4? The best answer will work in Lollipop, Marshmallow, and Nougat.
I would also very much appreciate an explanation as to why this happened, or any background information you can give. Thanks!
Is it xamarin? Create your alertdialog with just the context, don't use the theme.

Coloured Background of Action Button in Sweet Alert (Android)

I have written some code for showing a Dialog box using sweet alert library. It's a very popular library and contains couple of awesome features which are very useful for designing purpose and developing purpose as well. So please help to change the background color of Action button which are present at the bottom of the dialog box.
I am attaching the screen shot and as well as code. Please help me to fix this issue.
I only want to change the background color of Action Button.
MaterialDialog.Builder builder = new MaterialDialog.Builder(SignInActivity.this)
.title("Sign Up")
.titleColor(Color.BLACK)
.customView(R.layout.custom_dialog_sign_up, true)
.positiveText("Submit")
.negativeText("Cancel")
.positiveColorRes(R.color.black_color)
.negativeColorRes(R.color.gray_btn_bg_color)
.canceledOnTouchOutside(false)
.autoDismiss(false);
final MaterialDialog materialDialog = builder.build();
materialDialog.show();
it is pretty late to respond upon your question but, recently i face this issue and start digging about it on google but found nothing, so i started my own and found this perfect solution code and screen shot attached.
SweetAlertDialog sweetAlertDialogView;
sweetAlertDialogView = new SweetAlertDialog(ctx,SweetAlertDialog.ERROR_TYPE);
sweetAlertDialogView.setTitleText(ctx.getResources().getString(R.string.error_msg_oops_title))
.setContentText("Request failed :" + errMsg + " \n" + ctx.getResources().getString(R.string.error_msg_check_net_connection));
sweetAlertDialogView.show();
Button viewGroup = (Button) sweetAlertDialogView.findViewById(cn.pedant.SweetAlert.R.id.confirm_button);
if (viewGroup != null) {
Log.e(TAG, "showErrorMsg: Button view Found yep");
viewGroup.setBackgroundColor(viewGroup.getResources().getColor(R.color.colorSkyBlueButtonLoader));
} else {
Log.e(TAG, "showErrorMsg: Button view Null :( ");
}
from above logic i update the button color to dark sky blue blue, for any other help you can ask me in comment. i will try to resolve it with my best.
A far more easier way to accomplish this is to just overwrite following color values in your color.xml:
<color name="blue_btn_bg_color">#1976D2</color>
<color name="blue_btn_bg_pressed_color">#1565C0</color>

Xamarin ContentPage BackgroundImage property crashes app on Android

I'm using Xamarin Forms to produce a TabbedPage consisting of more ContentPages. This is the part of code causing trouble:
public void launchMainDesign(object s, EventArgs e) {
MainPage = new TabbedPage {
Children = {
new ContentPage {
Title = "Login",
Content = pages.loginContent,
BackgroundImage = "bgmain.jpg"
},
new ContentPage {
Title = "Sign Up",
Content = pages.signUpContent,
BackgroundImage = "bgmain.jpg"
}
}
};
}
It seems absolutely fine. I have both the images in my Drawable directory, with the build action set to "AndroidResource".
Whenever the launchMainDesign() function is fired by pressing a button, the app crashes immediately, both in emulator and a build version of the app on a tablet. Unfortunately, I can't test on iOS and WP.
I even tried putting the whole inside part of the function in a try/catch block and print out the exception, but the app just crashes nevertheless.
I am desperately trying to solve this simple problem for about a week now. No one seems to be having exactly the same issue as me. Weirdest thing is, I have a different app where I use exactly the same method and it works just fine. Can the Android Theme be causing this (I'm using Holo, in the working app, there's no theme specified)? That seems to be the only difference.
I also don't think this is caused by RAM struggles, as the image is only about 700 kilobytes (1080x1920) - for this example, I've only used one image.
It could be a memory issue, because even do the size is not big depending on the device resolution it might be trying to scale the image to the device dimensions.
Try checking this README:
https://github.com/xamarin/customer-success/blob/master/samples/Xamarin.Forms/SliderView/README.md
Explains Xamarin.Forms Android Image Memory Management so could help you get around the issue you might be having.

Android startActivity doesn't work for some images but not others

Sorry about the confusing question title, wasn't sure how better to phrase it...
The problem is that I have a bunch of downloaded image thumbnails on the screen. If any one of them is clicked, a new activity should be launched that features (amongst other things) a larger version of the image.
It works fine for some of the images, but I realised by happenstance that for more than half of the images it just does nothing. The code is executed (I get log messages) but nothing happens.
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(locationBitmap.bitmap);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View image) {
Log.i(this.getClass().getName(), "You selected location: " + locationBitmap.location);
Intent i = new Intent(context, AnswerActivity.class);
i.putExtra("question_text", question_text);
i.putExtra("question_title", question_title);
i.putExtra("location", locationBitmap.location);
i.putExtra("bitmap", locationBitmap.bitmap);
Log.d(this.getClass().getName(), "About to start the activity...");
context.startActivity(i);
Log.d(this.getClass().getName(), "Started the activity...");
}
});
All of the log messages are produced correctly, but sometimes the activity doesn't change and sometimes it does. Any ideas?
The answer seems to be that the bundle has a size limitation - some of the file's are exceeding it and some aren't.
Passing through the name of a file, rather than the bitmap itself, works.
Related question: Maximum length of Intent putExtra method? (Force close)
I think problem with getting image null.
check locationBitmap.bitmap is null or not put one condition if null then set default image else set imageView.setImageBitmap(locationBitmap.bitmap);
This type issue generate many user.

Animating a toast in android?

Am trying to animate my toast but have been unsuccessful so far. This is what I have in my onCreate():
ImageView image = new ImageView(this);
image.setImageResource(R.drawable.icon);
Animation move = new TranslateAnimation(0,100, 0, 100);
move.setDuration(2000);
move.setFillEnabled(true);
move.setFillAfter(true);
image.startAnimation(move);
Toast toast = new Toast(this);
toast.setView(image);
toast.show();
Have tried placing startAnimation() after displaying the toast, but that doesn't work either.
Toast notifications use a system template to determine how they are displayed. Short of modifying the Android source code, you can not create a special animation for your Toast message.
However, if possible you might be able to create a normal view and use that instead. One common method is to create a new Activity that has a transparent background with your modal toast message animated and displayed however you want.

Categories

Resources