This is Sample Project Which you can improve UI design & Coding skills .
1) First you need layout resource file.(alert_dialog.xml)
2)I'm create method in LoginActivity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/bg_round"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp">
<com.airbnb.lottie.LottieAnimationView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/lottie"
app:lottie_autoPlay="true"
app:lottie_rawRes="@raw/nointernet"
app:lottie_repeatCount="1000"
app:lottie_repeatMode="restart"
android:layout_marginTop="20dp"
android:elevation="2dp"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/baloo"
android:text="OOps!"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@color/blacks"
android:textStyle="bold"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="No Internet Connection found. \n Check yor connection."
android:textAlignment="center"
android:textStyle="bold"
android:fontFamily="@font/brandon_grotesque_black"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/blacks" />
<Button
android:id="@+id/bt_try_again"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="@drawable/button_style"
android:text="Try Again"
android:textAllCaps="false"
android:textColor="@color/white"
android:textStyle="bold" />
</LinearLayout>
bg_round drawable file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white"/>
<stroke android:width="1dp" android:color="@color/coloryellow" />
<corners android:radius="30dp"
/>
</shape>
LoginActivity
private void checkInternetAvailable() {
////////////Initialize ConnectionManager/////////////////
ConnectivityManager connectivityManager = (ConnectivityManager)
getApplicationContext().getSystemService(Context.
CONNECTIVITY_SERVICE);
//////////Get active network info////////////////////////
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
////////////////check network status////////////////////
if (networkInfo == null || !networkInfo.isConnected() ||
!networkInfo.isAvailable()) {
///////////when internet is inactive/////////////////
/////////initialize dialog//////////////////////////////
Dialog dialog = new Dialog(this);
////////set Content View///////////////////////////
dialog.setContentView(R.layout.alert_dialog);
///set outside touch////////
dialog.setCanceledOnTouchOutside(false);
/////set dialog width and height///////////
dialog.getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT);
//////////////set transparent Background///////////////
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//////set animation
dialog.getWindow().getAttributes().windowAnimations =
android.R.style.Animation_Dialog;
/////////Initialize dialog variable
Button btTryAgain = dialog.findViewById(R.id.bt_try_again);
//////Perform onClick listner
btTryAgain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//////call method
recreate();
}
});
//show dialog
dialog.show();
}
}
0 Comments