iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android Studio使用自定义对话框效果
  • 218
分享到

Android Studio使用自定义对话框效果

2024-04-02 19:04:59 218人浏览 独家记忆
摘要

Android Studio基础使用自定义对话框,供大家参考,具体内容如下 兼容低版本的APP运行 第一步:新建新的空白activity,布局XML设置如下 该APP的启动界面ac

Android Studio基础使用自定义对话框,供大家参考,具体内容如下

兼容低版本的APP运行

第一步:新建新的空白activity,布局XML设置如下

该APP的启动界面activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".MainActivity">
 
    <Button
        android:id="@+id/btn_single"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="显示单选对话框"/>
    <Button
        android:id="@+id/btn_alert_customer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="自定义对话框"/>
 
</LinearLayout>

自定义的对话框item_alert_dialog的布局XML设置

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".MainActivity">
 
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="自定义Dialog界面!"
        />
    <TextView
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:background="@mipmap/ic_launcher"/>
 
</LinearLayout>

第二步:在MainActivity.java中绑定布局xml

第三步:对话框实现抽象方式

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("单选对话框").setIcon(R.mipmap.ic_launcher).setSingleChoiceItems(new String[]{"中国", "德国", "日本"}, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(MainActivity.this,"选中的"+which,Toast.LENGTH_SHORT).show();
                    }
                });
                break;
            case R.id.btn_alert_customer:
                //setView(R.layout.item_alert_dialog)为自定义的对话框,或图片等等
                builder.setTitle("自定义对话框").setIcon(R.mipmap.ic_launcher).setView(R.layout.item_alert_dialog);
                break;
            }
        AlertDialog ad = builder.create();
        ad.show();
    }
}

第四步:运行APP效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: Android Studio使用自定义对话框效果

本文链接: https://www.lsjlt.com/news/149026.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android Studio使用自定义对话框效果
    Android Studio基础使用自定义对话框,供大家参考,具体内容如下 兼容低版本的APP运行 第一步:新建新的空白activity,布局XML设置如下 该APP的启动界面ac...
    99+
    2024-04-02
  • Android studio自定义对话框效果
    本文实例为大家分享了Android studio自定义对话框效果的具体代码,供大家参考,具体内容如下 实现步骤: 第一步:自定义.xml布局文件 <?xml ver...
    99+
    2024-04-02
  • Android Studio怎么使用自定义对话框效果
    这篇文章主要介绍了Android Studio怎么使用自定义对话框效果的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Android Studio怎么使用自定义对话框效果文章都会有所收获,下面...
    99+
    2023-06-30
  • android如何自定义对话框
    这篇文章给大家分享的是有关android如何自定义对话框的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。实现效果  定义dialog.xml (res/layout/dialog.xml)<...
    99+
    2023-06-22
  • Android中如何自定义对话框
    本文小编为大家详细介绍“Android中如何自定义对话框”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android中如何自定义对话框”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。本文测试的harbor的版本是...
    99+
    2023-06-29
  • android自定义带箭头对话框
    本文实例为大家分享了android自定义带箭头对话框的具体代码,供大家参考,具体内容如下 import android.content.Context; import andr...
    99+
    2024-04-02
  • android自定义对话框实例代码
    1.实现效果    2.定义dialog.xml (res/layout/dialog.xml) <?xml version="1.0" encoding="utf...
    99+
    2024-04-02
  • Android自定义加载框效果
    本文实例为大家分享了Android自定义加载框效果的具体代码,供大家参考,具体内容如下 效果图 菊花图标(mipmap-xxhdpi) 加载框圆角背景drawable <...
    99+
    2024-04-02
  • Android自定义弹框Dialog效果
    本文实例为大家分享了Android自定义弹框Dialog效果的具体代码,供大家参考,具体内容如下 1.dialog_delete.xml <xml version=...
    99+
    2024-04-02
  • Android自定义对话框的简单实现
    本文实例为大家分享了Android自定义对话框的具体实现代码,供大家参考,具体内容如下 1、定义对话框的布局 <xml version="1.0" encoding="utf-...
    99+
    2024-04-02
  • Android自定义样式圆角dialog对话框
    本文实例为大家分享了Android创建自定义样式圆角dialog对话框的具体代码,供大家参考,具体内容如下 效果如上,圆角对话框,标题和正文都可以自己设定 做法: 1.在res文件...
    99+
    2024-04-02
  • Android自定义弹出框dialog效果
    项目要用到弹出框,还要和苹果的样式一样(Android真是没地位),所以就自己定义了一个,不是很像(主要是没图),但是也还可以。废话不多说了,直接上代码先看布局文件<?xml version="1.0" encoding="u...
    99+
    2023-05-31
    android 弹出框 dialog
  • Android自定义对话框Dialog的简单实现
    本文着重研究了自定义对话框,通过一下步骤即可清晰的理解原理,通过更改界面设置和style类型,可以应用在各种各样适合自己的App中。首先来看一下效果图:首先是activity的界面点击了上述图片的按钮后,弹出对话框:点击对话框的确定按钮:点...
    99+
    2023-05-30
    android 对话框 dialog
  • Android如何自定义输入文本对话框?
    文章目录 0.引言1.创建示例工程2.输入文本对话框布局和功能设计3.主程序调用输入文本对话框 0.引言   笔者研究的课题涉及到安卓软件开发,在开发过程中,发现普通的显示消息对话框一般可...
    99+
    2023-10-26
    android java android studio
  • Android中怎么自定义AlertDialog对话框样式
    这篇文章给大家介绍Android中怎么自定义AlertDialog对话框样式,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。根据自己实际的需求,为AlertDialog创建一个布局,在此我需要定义一个如图所示的WIFI密...
    99+
    2023-05-30
    android alertdialog
  • Android怎么自定义弹框Dialog效果
    今天小编给大家分享一下Android怎么自定义弹框Dialog效果的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。具体效果如下...
    99+
    2023-06-30
  • Android怎么自定义样式圆角dialog对话框
    这篇文章主要介绍“Android怎么自定义样式圆角dialog对话框”,在日常操作中,相信很多人在Android怎么自定义样式圆角dialog对话框问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Android...
    99+
    2023-06-25
  • Android自定义view实现输入框效果
    本文实例为大家分享了Android自定义view实现输入框的具体代码,供大家参考,具体内容如下 自定义输入框的View package com.fenghongzhang.day...
    99+
    2024-04-02
  • Android如何自定义升级对话框示例详解
    前言本文主要给大家介绍了关于Android自定义升级对话框的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。实现的效果如下所示其实这也只是一个DialogFragment 而已,重点只是在于界面的设计想要使用做出这...
    99+
    2023-05-30
    android 自定义 升级对话框
  • Android中怎么自定义对话框位置及大小
    Android中怎么自定义对话框位置及大小,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。代码:package angel.devil;import an...
    99+
    2023-05-30
    android
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作