My "no internet" alert dialog is not showing in full screen and also to mention that my button after i click not refreshing just disappear..what should i do to change it to open in full screen, i also tried with setContentView too, but it not worked..
This is my code..
Class file:
public class NetworkChangeListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(!Common.isConnectedToInternet(context)){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
View view = LayoutInflater.from(context).inflate(R.layout.alert_dialog,null);
builder.setView(view);
AppCompatButton btnRetry = view.findViewById(R.id.btnRetry);
AlertDialog dialog = builder.create();
dialog.show();
dialog.setCancelable(false);
dialog.getWindow().setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
btnRetry.setOnClickListener(view1 -> {
dialog.dismiss();
onReceive(context,intent);
});
}
}
}
XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f7f7f7"
android:id="@ id/nointernet">
<ImageView
android:id="@ id/imageView"
android:layout_width="212dp"
android:layout_height="188dp"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true"
android:layout_marginTop="250dp"
android:src="@drawable/ic_baseline_signal_wifi_off_24"></ImageView>
<TextView
android:id="@ id/text"
android:layout_width="253dp"
android:layout_height="52dp"
android:text="Error!"
android:textAlignment="center"
android:textSize="25dp"
android:layout_below="@id/imageView"
android:layout_centerInParent="true"></TextView>
<TextView
android:id="@ id/text2"
android:layout_width="337dp"
android:layout_height="63dp"
android:text="No internet connection"
android:textAlignment="center"
android:textSize="21dp"
android:layout_below="@id/text"
android:layout_centerInParent="true"></TextView>
<Button
android:id="@ id/btnRetry"
android:layout_width="213dp"
android:layout_height="49dp"
android:text="Try again"
android:layout_below="@id/text2"
android:layout_centerInParent="true"></Button>
</RelativeLayout>
Main acitivity:
@Override
protected void onStart() {
IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(networkChangeListener,intentFilter);
super.onStart();
recreate();
}
@Override
protected void onStop() {
unregisterReceiver(networkChangeListener);
super.onStop();
}
CodePudding user response:
set minWidth and minHeight of 800dp/1000dp to RelativeLayout of your dialog layout file.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f7f7f7"
android:id="@ id/nointernet"
minWidth="1000dp"
minHeight="1000dp">
// rest of the views.
</RelativeLayout>
CodePudding user response:
i added this and it works fine..
<style>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="backgroundColor">#f7f7f7</item>
<item name="android:windowBackground">#f7f7f7</item>
</style>