Here's a simple alert box with customization. We create the alert box through a xml layout, here we can drag any type of widgets, text fields etc.. like spinners, edit text, image in a alert box.
To create simple alert box without creating xml layout check this link.
By creating alert box though xml layout it provides a wide variety of options to be inserted in a alert box easily.
Step 1 : Create an android project. And in layout folder create a new layout for alert box.
Customize your layout file how your alert box should look like.
custom_layout.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:src="@drawable/batman"
android:layout_width="match_parent"
android:layout_height="64dp"
android:text="LOGIN"
android:gravity="center"
android:textSize="35sp"
android:background="#FFFFBB33"/>
<EditText
android:id="@+id/username"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:hint="username" />
<EditText
android:id="@+id/password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="16dp"
android:fontFamily="sans-serif"
android:hint="password"/>
</LinearLayout>
Step 2 : In your main activity file create alert dialog and inflate the view for alert box.MainActivity.java :
package com.exam.sample;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
logout();
}
public void logout(){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = this.getLayoutInflater();
alertDialog.setView(inflater.inflate(R.layout.custom_layout, null));
/* When positive (yes/ok) is clicked */
alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
dialog.cancel(); // Your custom code
}
});
/* When negative (No/cancel) button is clicked*/
alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish(); // Your custom code
}
});
alertDialog.show();
}
}
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteData Science with Python training in chenni
Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
Great content thanks for sharing this informative blog which provided me technical information keep posting.
ReplyDeletejava training in marathahalli | java training in btm layout
java training in jayanagar | java training in electronic city
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeleteDevops training in sholinganallur
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteBlueprism training in btm
Blueprism online training
Outstanding blog post, I have marked your site so ideally I’ll see much more on this subject in the foreseeable future.
ReplyDeleteangularjs Training in chennai
angularjs-Training in pune
angularjs-Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
ReplyDeleteThanks for the great blog! keep posting.
selenium training in tambaram
selenium training in adyar
iOS Training in Chennai
French Classes in Chennai
Big Data Training in Chennai
java certification training in chennai
best java training
java j2ee training
the detailed explation of technology im happy to read this.its very helpful for me and future reference also.
ReplyDeleteRPA Training in Chennai
Robotics Process Automation Training in Chennai
RPA course in Chennai
Blue Prism Training in Chennai
UiPath Training in Chennai
After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience. Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeleteblue prism Training in Electronic City
Thanks for this wonderful blog it is really informative to all.keep update more information about this
ReplyDeleteaws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore
python Training in Bangalore
aws Training in Bangalore
I have visited this blog first time and i got a lot of informative data from here which is quiet helpful for me indeed. keep share a lot
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
Learn Oracle DataBase Administration for making your career as a shining sun with Infycle Technologies. Infycle Technologies offers the No.1 Oracle DBA training in Chennai, with total hands-on practical training of professional specialists in the field. In addition to that, it also offers numerous programming language tutors in the software industry such as Python, AWS, Hadoop, etc. Once after the training, interviews will be arranged for the candidates, so that, they can set their career without any struggle. Of all that, 200% placement assurance will be given here. To have the best career, call 7502633633 to Infycle Technologies and grab a free demo to know more.Top Oracle DBA Training in Chennai
ReplyDeletetuzla beko klima servisi
ReplyDeleteçekmeköy lg klima servisi
kartal daikin klima servisi
beykoz samsung klima servisi
beykoz mitsubishi klima servisi
maltepe mitsubishi klima servisi
kadıköy mitsubishi klima servisi
kartal vestel klima servisi
ümraniye vestel klima servisi