Behavior of an Activity as Dialog

2

I want to achieve the following, as you can see a Dialog at the top has a circular icon of close (x) . I have the Dialog but I need the mentioned icon, any ideas to get this or something similar?

I have converted a normal Layout in Dialog , this way. In the manifests I applied the following Style

Style

 <style name="formularios" parent="Base.Theme.AppCompat.Light.Dialog">
        <item name="android:background">@color/formulario</item>
        <item name="android:radius">@dimen/from</item>
    </style>

and then in the manifests I apply the style

android:theme="@style/formularios"
    
asked by Ashley G. 11.01.2017 в 14:50
source

2 answers

2

What you need is to create a CustomDialog which you will make from a% common% with transparent background , you can use an image to place there your options like for example the close button. Usually I used frameLayout .

Already in your activity you fill your dialogue with the Layout that you have created:

I'll give you a complete example so you can understand it much better

 private void alert_win() {

        //** Aquí empieza la parte que nos interesa**

        dialog = new Dialog(GameScreen.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//Aquí le das ele efecto de transparencia
        dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
        dialog.setContentView(R.layout.winner_dialog);//Aquí cargas el layout
        dialog.setCanceledOnTouchOutside(false); //Evita cerrar el diálogo cuando tocas fuera de el.

 //** Aquí termina la parte que nos interesa**


        Typeface typeFace=Typeface.createFromAsset(getAssets(), "bellosmcp.ttf");

        TextView moTextView = (TextView) dialog.findViewById(R.id.moTextView);
        moTextView.setTypeface(typeFace);
        moTextView.setText(String.valueOf(_turn_count));
        TextView matchTextView = (TextView) dialog.findViewById(R.id.matchTextView);
        matchTextView.setTypeface(typeFace);
        movesTextView.setTypeface(typeFace);
        matchTextView.setText(String.valueOf(_score));
        TextView pairstextView =(TextView) dialog.findViewById(R.id.pairstextView);
        pairstextView.setTypeface(typeFace);
        pairstextView.setText(Integer.toString(c));
        ImageView closeDialog = (ImageView) dialog.findViewById(R.id.close);
        TextView highScoreTextView = (TextView) dialog.findViewById(R.id.high_Score);
        highScoreTextView.setTypeface(typeFace);
        highScoreTextView.setText(String.valueOf(user.high_score));


.......
         //** Aquí colocas un button o imagebutton que cierre el diálogo**  
        closeDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                } else {
                    go_home();
                    send_score();
                }
                //display_unlocked_card_alert();


                display_unlocked_card_alert();


            }
        });


        ImageButton resetGame =(ImageButton) dialog.findViewById(R.id.resetGame);
        resetGame.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();

                    reset_game();

                display_unlocked_card_alert();




            }
        });

        dialog.show();

        Log.d(  TAG,"unlocked_check value 2 = " + unlocked_check);
    }

Dialogue content layout

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@android:color/transparent"
    android:id="@+id/winner"><![CDATA[
  android:padding="10dip">

    ]]>

    <ImageView
  android:id="@+id/about_logo"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
    android:layout_gravity="center"
  android:layout_centerHorizontal="true"
  android:src="@drawable/fondo_score"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:layout_marginBottom="10dip" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/high_score"
        android:id="@+id/highScore"
        android:paddingRight="10dp"
        android:scaleType="fitXY"
        android:layout_gravity="center"
        android:paddingLeft="50dp"
        android:layout_marginLeft="100dp"
        android:layout_marginBottom="50dp" />

    <ImageView
        android:id="@+id/gameResults"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/this_match"
        android:scaleType="fitXY"
        android:layout_marginRight="200dp"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/close"
        android:layout_gravity="center"
        android:paddingLeft="230dp" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/try_again_efects_image"
        android:id="@+id/resetGame"
        android:layout_below="@+id/pairstextView"
        android:layout_alignEnd="@+id/gameResults"
        android:layout_marginTop="125dp"
        android:layout_gravity="center"
        android:layout_marginRight="100dp"
        android:layout_marginLeft="20dp" />

    <TextView style="@style/match_results"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="This match"
        android:shadowColor="@color/text_shadow"
        android:shadowDx="-1"
        android:shadowDy="-1"
        android:shadowRadius="2"
        android:scaleType="fitCenter"
        android:id="@+id/matchTextView"
        android:gravity="center_horizontal"
        android:layout_above="@+id/moTextView"
        android:layout_gravity="center"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="40dp"
        android:layout_marginRight="80dp" />

    <TextView style="@style/match_results"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Moves"
        android:shadowColor="@color/text_shadow"
        android:shadowDx="-1"
        android:shadowDy="-1"
        android:shadowRadius="2"
        android:scaleType="fitCenter"
        android:id="@+id/moTextView"
        android:layout_centerVertical="true"
        android:layout_alignStart="@+id/matchTextView"
        android:layout_gravity="center"
        android:layout_marginRight="80dp"
        android:layout_marginTop="10dp" />

    <TextView style="@style/match_results"
        android:id="@+id/pairstextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pairs"
        android:shadowColor="@color/text_shadow"
        android:shadowDx="-1"
        android:shadowDy="-1"
        android:shadowRadius="2"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_alignBottom="@+id/gameResults"
        android:layout_alignParentStart="true"
        android:scaleType="fitCenter"
        android:layout_gravity="center"
        android:layout_marginRight="84dp"
        android:layout_marginTop="65dp" />

    <TextView style="@style/high_score"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Medium Text"
        android:id="@+id/high_Score"
        android:layout_gravity="center"
        android:layout_marginLeft="100dp"
        android:layout_marginBottom="40dp" />

    <ImageView
        android:layout_width="44dp"
        android:layout_height="44dp"
        android:background="@drawable/ic_close_dialog"
        android:id="@+id/close"
        android:layout_gravity="center"
        android:layout_marginLeft="160dp"
        android:layout_marginBottom="160dp"
        android:scaleType="fitXY" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/copa"
        android:id="@+id/imageView3"
        android:layout_gravity="center"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="60dp"
        android:layout_marginRight="10dp" />

</FrameLayout>

That stays like this:

As you can see you can create a dialogue from a layout or whatever you want, I use this type of dialog when I need one with many options or one that does not keep the common aspect.

    
answered by 11.01.2017 / 16:57
source
0

If you can, it's all a theme of layout I propose the following:

  • The celestial container would be the parent or the main view of the DialogFragment can be a RelativeLayout.

  • The red container would be the close button aligned to the right with margins as you need it and you put the id "@ + id / btn_cerrar".

  • The green container under the "close" button in a schematic second LinearLayout could be in this case for the options panel use the attribute layout_below="@ id / btn_close" for example.

Now the parent container is going to put a transparent background that is to make it appear that the "close" button is in the air or floating.

and the container under the "close" or the LinearLayout you will place a drawable made by you that has a white background rounded edge or whatever you need and ready already with that is left.

It's all left for you to do the programming of what each button does.

That's how I would do it and I've already had to do this kind of thing.

    
answered by 11.01.2017 в 16:46