Skip to content

Instantly share code, notes, and snippets.

@AkaashSaini
Created July 7, 2021 11:25
Show Gist options
  • Save AkaashSaini/073a0a98693d74ed9a5d2219d57c0c3a to your computer and use it in GitHub Desktop.
Save AkaashSaini/073a0a98693d74ed9a5d2219d57c0c3a to your computer and use it in GitHub Desktop.
Custom Dialog
Create a Dialog
Dialog d=new Dialog(MainActivity.this);
Set Following Properties
Dialog d=new Dialog(MainActivity.this);
d.setContentView(R.layout.dialog);
d.setTitle("Important Message....");
d.setCancelable(true);
d.show();
Create UI with name dialog.xml
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is very important!"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:text="The Time Table of First Mid Terms"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Complete Code
public class MainActivity extends ActionBarActivity
{
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button) findViewById(R.id.button1);
b1.setOnClickListener(new A());
}
class A implements OnClickListener
{
@Override
public void onClick(View arg0)
{
Dialog d=new Dialog(MainActivity.this);
d.setContentView(R.layout.dialog);
d.setTitle("Important Message....");
d.setCancelable(true);
d.show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment