Custom popup

Asked

Viewed 3,848 times

4

I want to do a custom popup, similar to the one in the photo, putting a button to close at the top and it centered in the middle of the screen, anyone know how I do it? I looked for some codes, but nothing very completeinserir a descrição da imagem aqui

  • This example of yours has a great chance (by appearance) of being a non-true Popup (Modal) Web. Loaded from an Android Webview, or may even be the result of a hybrid application produced with Phonegap (or some variation). I’m actually saying this, because the layout of Alertdialog It is a little complicated to customize (as far as I know), and I believe that this Popup is not built natively on Android. And if you want to program natively it will not be possible to play it

  • 2

    Fernando, it is possible to customize the Dialog this way, just take the title and the buttons. And using a Custom View. An example of full code is given in this question/answer: http://stackoverflow.com/questions/15173855/android-alertdialog-with-custom-view-and-rounded-corners.

  • Uhuh, cool @Wakim, didn’t know it, and didn’t believe it was possible with so little work, had already looked for something similar to this, not as "radical" as the question, but had not succeeded, and I left for the future since it was not something grounded at that time for the application, even so the question caught my attention. I will do a little more research on the subject. And thanks for the tip.

  • @Fernando, ok! Sometimes I marked and the OS itself removed the markings, I don’t know if it was momentary. Thanks for the warning.

  • Wakim thanks, that’s just what I needed.

1 answer

4


With Dialogfragment you get this way below

mButton.setOnclickListener(new OnclickListener(){
       test();

});

public void test(){
    Dialog dialog = new Dialog(this, R.style.FullHeightDialog);
    dialog.setContentView(R.layout.seu_layout_customizado);
    dialog.show();
}

Creation of XML

  • Create a Linearlayout root
  • Create another Linearlayout with the vertical orientation, where it will contain the X button, title and description.
  • Creates a View (<View android:layout_width="fill_parent" android:layout_height="1dp"/>) to represent the line. To represent this grouping of icons and text (gps, wifi and wireless network) creates a Relativelayout.
  • For the confirmation button, add in Linearlayout root.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="x"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Melhore..."/>
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Para garantir..."/>
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        gps
        rede
        wifi
        </RelativeLayout>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    

  • 1

    Douglas, all that remains is to include dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); in that solution. Otherwise the Dialog will put a slash to the title.

  • True, without adding the dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) is created with the titlebar.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.