I'm making a game and when the user wins, I want to have a dialog box show up like this:
I am new to android programming, and I was wondering what the best way of going about doing this.
Things I have thought about so far:
Creating a canvas and drawing it (but I'm using a Layout)
Using a dialog (but these seems like you can't customize the color/texture)
Any ideas?
Thanks
your requirement fullfill using creating custom dialog.simple you create layout.xml file for your dialog.and call from your requirment:
Dialog mDialog = new Dialog(this);
mDialog.setContentView(R.layout.activity);
mDialog.show();
more for custom dialog:http://androidexample.com/Custom_Dialog_-_Android_Example/index.php?view=article_discription&aid=88&aaid=111
Related
I'm new to android. Ok so what I want to do is dim everything except the lottieAnimationView whenever I make the lottieAnimationView visible and also make everything back to normal when I turn lottieAnimationView gone. I tried a piece of code but it doesn't work
Edit: Maybe its possible through making the lottieanimationview visible inside an alert dialog box so can someone provide the code for that.
You need to create Custom Dialog which contains LottieAnimationView through which you can achieve desire output.
You can get an idea that how to create Custom Dialog using below link.
How to create a Custom Dialog box in android?
Dialog with transparent background in Android
I am trying to implement a simple logic in my application where the user is shown a popup (after sometime of application launch). The popup simply shows a TextView with some info message. This message is refreshed every time the application is launched and a new message is shown.
The UI of the popup matches my application UI - here maybe just popup background images is needed. Also one close button (X) is shown at the top right corner of the popup - to close this popup.
Logic of Showing Message: I have a String array having some 100 strings stored in it. I randomly pick one string from this array and populate the popup TextView showing the message. Please suggest if there is any better approach than what I am doing already here. Also is it possible to logic that if one message is picked then the same message is not picked until the other messages are shown at least once?
Logic of Showing Popup: This is what I am not able to implement. I do not want to anchor the popup with any user Event or Button click. I simply wants to show the message after some time - say
Thread.sleep(3000);
Now I have tried to use PopupWindow for this using the below code.
PopupWindow infoPopup;
LinearLayout infoLayout;
TextView infoTextView;
Button infoButton;
infoTextView = new TextView(this);
infoTextView.setText("Testing Popup Text");
infoTextView.setPadding(10,10,10,10);
infoButton = new Button(this);
infoButton.setText("Close");
infoLayout = new LinearLayout(this);
infoLayout.setOrientation(LinearLayout.VERTICAL);
infoLayout.addView(infoTextView);
infoLayout.addView(infoButton);
infoPopup = new PopupWindow(infoLayout,LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
infoPopup.setContentView(infoLayout);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
infoPopup.showAtLocation((CoordinatorLayout)findViewById(R.id.main_content),Gravity.CENTER,100,100);
But this popup is showing error at the last line giving null pointer on my
(CoordinatorLayout)findViewById(R.id.main_content)
parameter.
The issue that I am getting are:
First of all, I am not sure if this is the right approach of showing a custom UI popup. I am aware of AlertDialog but not sure which is the best option to go in this case - Please suggest.
Why the CoordinatorLayout is showing null pointer?
How to implement the top right (X) button logic in this Popup ?
1. Yes there are so many options for showing a custom UI popup in Android. You might select one from PopupWindow, AlertDialog or Dialog Activity. You need to decide which suits you best.
If you need to customize your UI a lot and have to show a list or some complex GUI then I would suggest you launch an Activity with theme.Dialog. Just set the theme of the Activity to something like this android:theme="#android:style/Theme.Holo.Light.Dialog". There's a plenty of tutorials for implementing a dialog Activity.
PopupWindow is another tool to customize your custom pop up anywhere in the screen. If you're showing this popup always in the middle of the screen, then I would like to suggest not to use this. The AlertDialog should work fine.
AlertDialog has many variants and as far as I can assume your problem, this one suits you best. You can have a cross button too in the top-right corner of the dialog (You can set the icons anywhere, as you can provide a custom layout to an AlertDialog). Personally I use this library to provide a custom layout to my AlertDialog. You can have a look at this too.
2. The NullPointerException is simple. Your layout doesn't have any id named main_content. Post your logcat if this doesn't solve your problem. Post the layout too.
3. As I've told you earlier, I use the library to provide a custom layout to an AlertDialog and you can have a look at it too. So after implementing this library you can easily design your own layout with a cross button and implement the onClick functionalities easily.
Hope this helps.
Activity with theme Dialog.
This is not a good idea. It looks like a pop-up, but you can't click outside the pop-up to close it.
PopupWindow
It will stop the application. When the user finish clicking the pop-up, the application can work again.
AlertDialog
The best one, it will not stop the application and can be closed by clicking outside the dialog.
So I have this piece of coding that I can't get to work: I have searched on the webs, and always found the same answer, but for some reason it just won't work. Any idea why? This is my code:
final Dialog dialog = new Dialog(RegisterActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
dialog.setContentView(R.layout.dialog_register_info_1);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
I have tried putting the dialog.getWindow().setSoftInputMode() behind the setContentView() too, but that didn't work either. The dialog only has a .xml file, so no activity.
Thanks in advance
I'm not sure if this is what you were looking for, but I wanted the dialog to appear above the keyboard and not behind it. What I did was this:
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Is this possible to use lwuit.Dialog with javax.microedition.lcdui.Canvas in wireless toolkit 2.5.2?
I created a canvas to write contents when I press mobile keys(for Example if I press "A" it will be written on the screen using paint function). Now I want to show a dialog or PopUp window when I press any key from mobile. Is it possible to show dialog when am using Canvas?
say some example,
public class Mycanvas extends Canvas implement ActionListener
{
Dialog dialog=new Dialog();
}
Ok, I think you must do that. The right thing in LWUIT is using Dialog.
Create a Dialog using new. i.e. Dialog d = new Dialog()
The next step is filling the title and body with Dialog.setTitle(String text) or putting something inside the Dialog's layout.
When your Dialog is ready to be shown, you must call to Dialog.show() and when you want to remove it, call to Dialog.dispose()
Take a look here
Is this possible to use lwuit.Dialog with javax.microedition.lcdui.Canvas in wireless toolkit 2.5.2?
If it is for debugging purpose you can use Alert instead. Here's an example how you can use Alert:
//you need to import javax.microedition.lcdui;
Alert alert = new Alert("Info", "Here's the key code/string", null, AlertType.INFO);
alert.setTimeout(3000); // for 3 seconds
display.setCurrent(alert, yourcanvasname); // so that it goes to back to your canvas after displaying the alert
Alert works fine with both forms and canvases.
I'm using the following tutorial http://developer.android.com/resources/tutorials/views/hello-mapview.html in order to create a map view and plot points on to it. I have all of that done fine but now I'd like to embed an image and even audio within the Alert dialogs that pop up. Is this possible in the current context? How would I do it?
You need to create a Custom Dialog.