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

Android studio自定义对话框效果

2024-04-02 19:04:59 954人浏览 八月长安
摘要

本文实例为大家分享了Android studio自定义对话框效果的具体代码,供大家参考,具体内容如下 实现步骤: 第一步:自定义.xml布局文件 <?xml ver

本文实例为大家分享了Android studio自定义对话框效果的具体代码,供大家参考,具体内容如下

实现步骤:

第一步:自定义.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:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="提示"
        android:background="@drawable/click"
        android:textSize="28sp"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:gravity="center"
        android:text="你真的要离开吗"
        android:textColor="#ff0400"
        android:background="@drawable/background"
        android:textSize="28sp"/>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="50sp"
        android:orientation="horizontal"
        android:background="@drawable/bb"
        android:gravity="center">
        <Button
            android:id="@+id/but"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="残忍离开"
            android:textSize="24sp"/>
    </LinearLayout>

</LinearLayout>

第二步:获取layoutInflater对象
第三步:调用inflater()方法获取View对象
第四步:调用Builder对象的setView()方法设置View
第五步:获取输入内容或者监听事件等

默认布局文件:.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">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="对话框"
        android:onClick="onclick"/>
</LinearLayout>

.java:


package com.example.catalogin;

import android.app.Dialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main2);
    }
    
    Dialog dialog;
    public void  onclick(View v){
        LayoutInflater inflater=LayoutInflater.from( this );
        View myview=inflater.inflate(R.layout.catalogin,null);//引用自定义布局
        AlertDialog.Builder builder=new AlertDialog.Builder( this );
        builder.setView( myview );
        dialog=builder.create();//创建对话框
        dialog.show();//显示对话框
        myview.findViewById(R.id.but).setOnClickListener( new View.OnClickListener() {//获取布局里面按钮
            @Override
            public void onClick(View v) {
                dialog.dismiss();//点击按钮对话框消失
                Toast.makeText( Main2Activity.this, "点击了残忍离开", Toast.LENGTH_SHORT ).show();
            }
        } );
    }
}

点击对话框

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

--结束END--

本文标题: Android studio自定义对话框效果

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

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

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

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

下载Word文档
猜你喜欢
  • Android studio自定义对话框效果
    本文实例为大家分享了Android studio自定义对话框效果的具体代码,供大家参考,具体内容如下 实现步骤: 第一步:自定义.xml布局文件 <?xml ver...
    99+
    2022-11-12
  • Android Studio使用自定义对话框效果
    Android Studio基础使用自定义对话框,供大家参考,具体内容如下 兼容低版本的APP运行 第一步:新建新的空白activity,布局XML设置如下 该APP的启动界面ac...
    99+
    2022-11-13
  • Android Studio怎么使用自定义对话框效果
    这篇文章主要介绍了Android Studio怎么使用自定义对话框效果的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Android Studio怎么使用自定义对话框效果文章都会有所收获,下面...
    99+
    2023-06-30
  • android自定义AlertDialog对话框
    前面一篇文章//www.jb51.net/article/103036.htm介绍了alertDialog的四种简单使用,但是有些时候为了让整个app的风格统一,或者说前面的四...
    99+
    2022-06-06
    alertdialog Android
  • Android自定义对话框Dialog
    本文简单介绍自定义对话框Dialog的使用,代码和结构都非常简单,目的是能够快速使用自定义对话框,在本文中不具体讲解对话框的高级使用。 实现步骤 首先需要自己在我们的.xml文...
    99+
    2022-06-06
    dialog Android
  • Android 自定义对话框 showSetPwdDialog
    样式如下所示: 布局: layout   dialog_set_pwd.xml <?xml version="." encoding="utf-"&...
    99+
    2022-06-06
    自定义 Android
  • Android自定义等待对话框
    最近,看了好多的APP的等待对话框,发现自己的太lower,于是就研究了一番,最后经过苦心努力,实现一个。 自定义一个LoadingIndicatorView(extend...
    99+
    2022-06-06
    Android
  • android如何自定义对话框
    这篇文章给大家分享的是有关android如何自定义对话框的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。实现效果  定义dialog.xml (res/layout/dialog.xml)<...
    99+
    2023-06-22
  • Android常用的AlertDialog对话框及自定义对话框
    常用的Dialog有确认对话框,单选按钮对话框,多选按钮对话框,复选按钮对话框另外还有自定义的对话框 AlertDialog的常用方法 setTitle:为对话框设置标题 se...
    99+
    2022-06-06
    自定义 alertdialog Android
  • android自定义带箭头对话框
    本文实例为大家分享了android自定义带箭头对话框的具体代码,供大家参考,具体内容如下 import android.content.Context; import andr...
    99+
    2022-11-11
  • Android中如何自定义对话框
    本文小编为大家详细介绍“Android中如何自定义对话框”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android中如何自定义对话框”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。本文测试的harbor的版本是...
    99+
    2023-06-29
  • android自定义对话框实例代码
    1.实现效果    2.定义dialog.xml (res/layout/dialog.xml) <?xml version="1.0" encoding="utf...
    99+
    2022-11-12
  • Android基础篇-对话框总结(普通对话框,单选对话框,多选对话框,自定义对话框)
    一:AlterDialog对话框 2:对话框圆角显示(在drawable下创建radiu...
    99+
    2022-06-06
    自定义 Android
  • Android自定义加载框效果
    本文实例为大家分享了Android自定义加载框效果的具体代码,供大家参考,具体内容如下 效果图 菊花图标(mipmap-xxhdpi) 加载框圆角背景drawable <...
    99+
    2022-11-12
  • Android自定义弹框Dialog效果
    本文实例为大家分享了Android自定义弹框Dialog效果的具体代码,供大家参考,具体内容如下 1.dialog_delete.xml <xml version=...
    99+
    2022-11-13
  • Android对话框自定义标题 对话框标题美化操作
    Android自带的对话框标题不好看,如果我们需要给弹出的对话框设置一个自己定义的标题,可以使用AlertDialog.Builder的setCustomTitle()方法。&...
    99+
    2022-06-06
    自定义 Android
  • Android自定义样式圆角dialog对话框
    本文实例为大家分享了Android创建自定义样式圆角dialog对话框的具体代码,供大家参考,具体内容如下 效果如上,圆角对话框,标题和正文都可以自己设定 做法: 1.在res文件...
    99+
    2022-11-12
  • Android自定义对话框的简单实现
    本文实例为大家分享了Android自定义对话框的具体实现代码,供大家参考,具体内容如下 1、定义对话框的布局 <xml version="1.0" encoding="utf-...
    99+
    2022-11-13
  • Android自定义弹出框dialog效果
    项目要用到弹出框,还要和苹果的样式一样(Android真是没地位),所以就自己定义了一个,不是很像(主要是没图),但是也还可以。废话不多说了,直接上代码先看布局文件<?xml version="1.0" encoding="u...
    99+
    2023-05-31
    android 弹出框 dialog
  • Android如何自定义输入文本对话框?
    文章目录 0.引言1.创建示例工程2.输入文本对话框布局和功能设计3.主程序调用输入文本对话框 0.引言   笔者研究的课题涉及到安卓软件开发,在开发过程中,发现普通的显示消息对话框一般可...
    99+
    2023-10-26
    android java android studio
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作