Android popup?

I am new to Android development, so I need to know what is the ideal and efficient way to create pop-ups like this in Android, basically it was easy to make pop-up and processing in iOS, but how to get started is to use a layout or something- for example, write me a link or a guide to make popover in android available for activity.

+4
source share
5 answers
import android.app.*;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.*;

public class ShowPopUp extends Activity {

PopupWindow popUp;
LinearLayout layout;
TextView tv;
LayoutParams params;
LinearLayout mainLayout;
Button but;
boolean click = true;


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    popUp = new PopupWindow(this);
    layout = new LinearLayout(this);
    mainLayout = new LinearLayout(this);
    tv = new TextView(this);
    but = new Button(this);
    but.setText("Click Me");
    but.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (click) {
                popUp.showAtLocation(mainLayout, Gravity.BOTTOM, 10, 10);
                popUp.update(50, 50, 300, 80);
                click = false;
            } else {
                popUp.dismiss();
                click = true;
            }
        }

    });
    params = new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    layout.setOrientation(LinearLayout.VERTICAL);
    tv.setText("Hi this is a sample text for popup window");
    layout.addView(tv, params);
    popUp.setContentView(layout);
    // popUp.showAtLocation(layout, Gravity.BOTTOM, 10, 10);
    mainLayout.addView(but, params);
    setContentView(mainLayout);
       }
   }
+1
source
private PopupWindow pwindo;
private void initiatePopupWindow() {
        try {
// We need to get the instance of the LayoutInflater
            LayoutInflater inflater = (LayoutInflater) AndroidAudioPlayer.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.your_layout_Screen,
                    (ViewGroup) findViewById(R.id.popup_element));
            pwindo = new PopupWindow(layout, 400, 600, true);
            pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

            Button btnClosePopup = (Button) layout.findViewById(R.id.button);
            btnClosePopup.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pwindo.dismiss();
                }
            });

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

For more trendy and good looking dialogs, take a look at this Pedant Sweet alert dialog library.

+4
source
+1

PopupWindow.

, . . . , .

PopupWindow Android

private PopupWindow pw;
private void initiatePopupWindow() {
    try {
        //We need to get the instance of the LayoutInflater, use the context of this activity
        LayoutInflater inflater = (LayoutInflater) ConfirmActivity.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //Inflate the view from a predefined XML layout
        View layout = inflater.inflate(R.layout.popup_layout,
                (ViewGroup) findViewById(R.id.popup_element));
        // create a 300px width and 470px height PopupWindow
        pw = new PopupWindow(layout, 300, 470, true);
        // display the popup in the center
        pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

        mResultText = (TextView) layout.findViewById(R.id.server_status_text);
        Button cancelButton = (Button) layout.findViewById(R.id.end_data_send_button);
        makeBlack(cancelButton);
        cancelButton.setOnClickListener(cancel_button_click_listener);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

private OnClickListener cancel_button_click_listener = new OnClickListener() {
    public void onClick(View v) {
        pw.dismiss();
    }
};
+1

s : xml ccc.xml :

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffee"
android:orientation="vertical"
android:theme="@style/AppTheme.NoActionBar"
>


<ImageView
    android:layout_width="60dp"
    android:layout_marginTop="100dp"
    android:layout_height="60dp"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/check"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_height="wrap_content"
    android:text="Invitaton Sent Sucessfully"
    android:layout_gravity="center_horizontal"
    android:textStyle="bold"
    android:textSize="15dp"
    /></LinearLayout>

, :

 b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Dialog d=new Dialog(MainActivity.this);
            d.setContentView(R.layout.ccc);
            d.show();



        }
    });
0

Source: https://habr.com/ru/post/1620251/


All Articles