Gravity; import android. LayoutInflater; import android. View; import android. LayoutParams; import android. Button; import android. LinearLayout; import android. Context ;. AppCompatActivity ;. Bundle ;. Gravity ;. LayoutInflater ;.
View ;. LayoutParams ;. Button ;. The button on the pop-up is given an OnClickListener so that the pop-up can be closed if not familiar with coding event handlers see the article Different Ways to Code Android Event Listeners. A touch event outside of the pop-up will also close it. The trick here is to call setBackgroundDrawable with a transparent drawable. This allows for screen presses outside of the pop-up to also close the pop-up:.
The following listing is for a simple Activity with a button that has an OnCLickListener to call the showWinners function that is described above. The names of the medal winners and there scores are simple variables, in a real app game they would come from the game results.
This is the complete code for the example in action shown at the beginning of the article:. Bookmark this page in your browser so that you can use the code as a template for future projects that require a pop-up. Author: Daniel S. Fowler Published: Updated: Build websites quickly and publish easily. For beginner to expert. Pop-up Window in Android The main screen for an Activity is not the only way to interact with the user of an app. How to Display A Smaller Window on Top of an Activity There are different ways in Android to pop-up a brief window over the current Activity screen, these include: The Toast class — to display brief informational only message.
The Dialog class, managed by a DialogFragment — to support a flexible input that can display information and can ask for inputs or choices. There are several built in sub-classes including: AlertDialog — supports buttons from zero to three , list selections, check boxes and radio buttons see the article About Box in Android App Using AlertBuilder. ProgressDialog — supports a progress bar or wheel and supports buttons because it extends AlertDialog.
DatePickerDialog — supports selecting a date. TimePickerDialog — supports a time selection. The PopupWindow class — allows a View to float on top of an existing activity. Suitable for custom informational messages. The Android developer PopupWindow documention gives this class overview: "This class represents a popup window that can be used to display an arbitrary view. The steps for this example project and code are: Create a new project in Android Studio. Design the pop-up window. Add the code to load and populate the pop-up window.
MartinezToni, I'm not sure why either. Show 2 more comments. Here, I am giving you a demo example. See this and customize it according to your need. Dinesh Sharma Dinesh Sharma Any solution for this stackoverflow. Max Alibaev 5 5 silver badges 16 16 bronze badges. Rejinderi Rejinderi LEFT, 40, 40 ; pView. Chris Sullivan Chris Sullivan 51 1 1 silver badge 1 1 bronze badge.
Jason Plank 2, 4 4 gold badges 30 30 silver badges 39 39 bronze badges. How can i fix the location of the button — jennifer.
SharpCx SharpCx 49 1 1 silver badge 2 2 bronze badges. Edit your style. Dialog provides a android poup-up theme. Pavel Smirnov 4, 3 3 gold badges 15 15 silver badges 25 25 bronze badges.
Fernando Lopes Fernando Lopes 1. The Overflow Blog. Who owns this outage? Building intelligent escalation chains for modern SRE.
0コメント