1. MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showDialog();
}
private void showDialog(){
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.customdialog);
Button btnOk = (Button)dialog.findViewById(R.id.button);
btnOk.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
2. customdialog.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="138dp"
android:layout_marginTop="113dp"
android:layout_marginEnd="186dp"
android:text="OK"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="169dp"
android:layout_marginTop="141dp"
android:layout_marginEnd="184dp"
android:text="This is custom dialog"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="This is custom dialog" />
</androidx.constraintlayout.widget.ConstraintLayout>
THE END
Pages
- Home
- How To Start / Create a new project in Android Stu...
- How To Open Existing Project in Android Studio
- How To Create Listview
- How To Create AlertDialog
- How To Create AutoCompleteTextView
- How To Create EditText with Custom Shape
- How to Create Spinner
- How to Watch Drama in Android
- How to Record Screen in Android
- How to Create Custom GridView in Android Studio
- How To Pass List Object and Display in Custom Listview
- How to use Webview in android studio to load URL
- How To Use Custom Dialog Tutorial
Subscribe to:
Posts (Atom)
Welcome To My Android Tutorial Lesson. Now this blogger cover : Android Studio Tutorial 1. How To Start / Create a new project...
No comments:
Post a Comment