0

I'm creating a web view android application in android studio. In this, I'm showing a dialogue box for No Internet connection and everything is working very good. But I want to set the height and width of the dialogue box to full screen in android studio? I am unable to do it in the below code and a screenshot of the app I did. I did everything to make the dialogue box full screen but nothing works. please help me with this project.

here is the screenshot

package com.example.demo2;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;


public class MyReceiver extends BroadcastReceiver {
   ConnectivityManager connectivityManager;
   NetworkInfo networkInfo;
   AlertDialog.Builder builder;
   private AlertDialog alertdialog;

   @Override
   public void onReceive(final Context context, Intent intent) {
       connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
       if (connectivityManager != null){
                networkInfo  =connectivityManager.getActiveNetworkInfo();
           if (networkInfo !=null && networkInfo.isConnected()){

               if (alertdialog!=null) {
                   alertdialog.dismiss();
               }
           }
           else {
               builder =new AlertDialog.Builder(context);
               View view = LayoutInflater.from(context).inflate(R.layout.internetconnection,null);
               builder.setView(view);
               builder.setCancelable(false);
               builder.create();
               alertdialog =  builder.show();
               view.findViewById(R.id.cancel_internet)
                   .setOnClickListener(new View.OnClickListener() {
                       @Override
                       public void onClick(View view) {
                           alertdialog.dismiss();
                           System.exit(0);
                       }
                   });
               view.findViewById(R.id.interner_settings)
                   .setOnClickListener(new View.OnClickListener() {
                       @Override
                       public void onClick(View view) {
                           context.startActivity(new Intent(Settings.ACTION_SETTINGS));
                       }
                   });
            }
        }

    }
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="#ba000000"
     android:orientation="vertical">

     <TextView
         android:id="@+id/noInternet"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_centerHorizontal="true"
         android:layout_marginLeft="15dp"
         android:layout_marginTop="270dp"
         android:fontFamily="sans-serif"
         android:text="No Network Connection"
         android:textColor="#fff"
         android:textSize="20dp" />

     <TextView
         android:id="@+id/interneterror"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@+id/noInternet"
         android:layout_centerHorizontal="true"
         android:layout_margin="15dp"
         android:text="A network connection is required to complete this task.Please connect to a Wi-Fi or cellular network."
         android:textColor="#fff"
         android:textSize="16sp"
         android:textStyle="bold" />

     <TextView
         android:id="@+id/cancel_internet"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@+id/interneterror"
         android:layout_marginLeft="100dp"
         android:layout_marginBottom="15dp"

         android:text="CANCEL"
         android:textColor="#ef9608"
         android:textSize="15sp"
         android:textStyle="bold" />

     <TextView
         android:id="@+id/interner_settings"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignTop="@+id/cancel_internet"
         android:layout_marginLeft="50sp"
         android:layout_toRightOf="@+id/cancel_internet"
         android:text="SETTINGS"
         android:textColor="#ef9608"
         android:textSize="15sp"
         android:textStyle="bold" />

</RelativeLayout>
nKognito
  • 6,297
  • 17
  • 77
  • 138
  • 4
    Does this answer your question? [How to set dialog to show in full screen?](https://stackoverflow.com/questions/6329360/how-to-set-dialog-to-show-in-full-screen) – AgentP Jun 21 '20 at 07:12
  • 1
    Imo that's misuse of dialog. Better use DialogFragment then. – ror Jun 21 '20 at 07:25
  • see here: https://stackoverflow.com/questions/28513616/android-get-full-width-for-custom-dialog/28519059 – Phantom Lord Jun 21 '20 at 09:56

0 Answers0