Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Custom Dialog effects in Android Studio

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the Android Studio how to use the custom dialog box effect related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this Android Studio how to use the custom dialog box effect article will have a harvest, let's take a look at it.

Compatible with lower versions of APP

Step 1: create a new blank activity with the following layout XML settings

The startup interface of the APP activity_main.xml

Layout XML settings for customized dialog box item_alert_dialog

Step 2: bind layout xml in MainActivity.java

Step 3: the dialog box implements the abstract way

Package com.xwb.zdydhk;import androidx.appcompat.app.AlertDialog;import androidx.appcompat.app.AppCompatActivity;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.Toast;public class MainActivity extends AppCompatActivity implements View.OnClickListener {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); Button btn_single = findViewById (R.id.btn_single) Btn_single.setOnClickListener (this); Button btn_alert_customer = findViewById (R.id.btn_alert_customer); btn_alert_customer.setOnClickListener (this);} @ Override public void onClick (View v) {AlertDialog.Builder builder = new AlertDialog.Builder (this) Switch (v.getId ()) {case R.id.btn_single: builder.setTitle ("Radio Dialog Box") .setIcon (R.mipmap.ic_launcher) .setSingleChoiceItems (new String [] {"China", "Germany", "Japan"}, 0, new DialogInterface.OnClickListener () {@ Override public void onClick (DialogInterface dialog) Int which) {Toast.makeText (MainActivity.this, "selected" + which,Toast.LENGTH_SHORT) .show () }}); break; case R.id.btn_alert_customer: / / setView (R.layout.item_alert_dialog) is a custom dialog box, or builder.setTitle ("custom dialog box") .setIcon (R.mipmap.ic_launcher) .setView (R.layout.item_alert_dialog) Break;} AlertDialog ad = builder.create (); ad.show ();}}

Step 4: run the APP effect

This is the end of the article on "how to use custom dialog box effects in Android Studio". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use custom dialog box effects in Android Studio". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report