Cov txheej txheem:

HelloWorld Nrog Tawm Tawm Khawm AndroidStudio: 4 Kauj Ruam
HelloWorld Nrog Tawm Tawm Khawm AndroidStudio: 4 Kauj Ruam

Video: HelloWorld Nrog Tawm Tawm Khawm AndroidStudio: 4 Kauj Ruam

Video: HelloWorld Nrog Tawm Tawm Khawm AndroidStudio: 4 Kauj Ruam
Video: И ЭТО ТОЖЕ ДАГЕСТАН? Приключения в долине реки Баараор. БОЛЬШОЙ ВЫПУСК (Путешествие по Дагестану #3) 2024, Kaum ib hlis
Anonim
HelloWorld Nrog Tawm Khawm AndroidStudio
HelloWorld Nrog Tawm Khawm AndroidStudio
HelloWorld Nrog Tawm Khawm AndroidStudio
HelloWorld Nrog Tawm Khawm AndroidStudio

Cov ntawv qhia no yuav qhia koj li cas los tsim Android App uas tso saib Hello World text thiab Exit khawm kom tawm ntawm qhov haujlwm.

Kauj Ruam 1: Tsim Txoj Haujlwm Tshiab

Qhib Android Studio thiab tsim txoj haujlwm tshiab. Npe koj txoj haujlwm tshiab li HelloWorld thiab ntxiv Kev Ua Haujlwm Tsis Txaus.

Kauj ruam 2: Kho qhov Activity_main.xml

Ntxiv cov ntawv nyeem tshiab thiab khawm (raws li qhia hauv qab no) hauv res> layout> activity_main.xml.

android: id = "@+id/btn_logout" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@+id/textView" android: layout_centerHorizontal = "tseeb" android: text = "Exit" android: textColor = "@xim/dub"/>

Txij li thaum peb siv cov xim rau cov ntawv, ntxiv cov peev txheej tshiab hauv color.xml. Mus rau res> qhov tseem ceeb> xim.xml thiab ntxiv cov cai hauv qab no

#0d0c0c>

Kauj ruam 3: Tam sim no, Kho qhov MainActivity.java

Ntxiv cov cai hauv qab no rau OnCreate () txoj hauv kev MainActivity.java

Peb ntxiv OnClickListener ua haujlwm rau lub pob yog li thaum twg tus neeg siv tau nyem rau ntawm lub pob qhov kev sib tham yuav tshwm nrog qhov ceeb toom "Koj puas xav tawm?". Ob txoj kev xaiv yuav muab rau tus neeg siv, "Yog …" kom tawm thiab "Tsis yog …" kaw qhov kev sib tham thiab rov qab mus rau qhov tseem ceeb.

Khawm btnlogout = (Khawm) findViewById (R.id.btn_logout);

btnlogout.setOnClickListener (Saib tshiab. OnClickListener () {@Override pej xeem void onClick (Saib pom) {zaum kawg AlertDialog. Builder builder = tshiab AlertDialog. Builder (MainActivity.this); builder.setTitle ("Tawm"); builder.setMessage ("Koj puas xav tawm ??"); builder.setPositiveButton ("Yog. Tawm tam sim no!", Tshiab DialogInterface. OnClickListener () {@Override pej xeem void onClick (DialogInterface dialogInterface, int i) tiav ();}}); builder.setNegativeButton ("Tsis yog tam sim no", DialogInterface tshiab. OnClickListener () {@Override pej xeem void onClick (DialogInterface dialogInterface, int i) dialogInterface.dismiss ();}}); AlertDialog dialog = builder.create (); dialog.sh ();}});

Kauj ruam 4: Ua tiav

Tam sim no, koj tuaj yeem khiav lub app.

Hmoov zoo

Cov lej tag nrho nyob ntawm no:

Pom zoo: