Как установить высоту и ширину диалогового окна на полный экран в студии android? - PullRequest
0 голосов
/ 21 июня 2020

Я создаю приложение веб-просмотра android в студии android. Здесь я показываю диалоговое окно для подключения Нет Inte rnet, и все работает очень хорошо. Но я хочу установить высоту и ширину диалогового окна на весь экран в студии android? Я не могу сделать это в приведенном ниже коде и на снимке экрана приложения, которое я сделал. Я сделал все, чтобы диалоговое окно было полноэкранным, но ничего не работает. пожалуйста, помогите мне с этим проектом.

вот скриншот

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>
...