Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

How to create a popup window (PopupWindow) in Android

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onButtonShowPopupWindowClick(View view) {

        // inflate the layout of the popup window
        LayoutInflater inflater = (LayoutInflater)
                getSystemService(LAYOUT_INFLATER_SERVICE);
        View popupView = inflater.inflate(R.layout.popup_window, null);

        // create the popup window
        int width = LinearLayout.LayoutParams.WRAP_CONTENT;
        int height = LinearLayout.LayoutParams.WRAP_CONTENT;
        boolean focusable = true; // lets taps outside the popup also dismiss it
        final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);

        // show the popup window
        // which view you pass in doesn't matter, it is only used for the window tolken
        popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);

        // dismiss the popup window when touched
        popupView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                popupWindow.dismiss();
                return true;
            }
        });
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: string to float java 
Java :: android studio listview arrayadapter 
Java :: how to use random bound on doubles java 
Java :: kmp java 
Java :: android studio breakpoint not working 
Java :: define a list java 
Java :: default method in java 
Java :: unprocessed continuation reference(s) remaining name 
Java :: java cast int to string 
Java :: java loop 
Java :: java triangle 
Java :: play mp3 android java 
Java :: modal css react 
Java :: java method return list 
Java :: string to char in java 
Java :: java empty array 
Java :: java remove space at the end of string 
Java :: java csv line split 
Java :: split number java 
Java :: integer to string java 
Java :: does finally block executed after crash 
Java :: spinner get selected index 
Java :: code for checking android build version 
Java :: arraylist syntax in java 
Java :: redondear a 2 decimales java 
Java :: javac clear 
Java :: how to fill a 2d array in java 
Java :: java read file 
Java :: how to format a double in java to 2 decimal places 
Java :: java run cmd 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =