前言:Android消息提示笔记,刚刚接触Android

1.静态方法Toast

直接调用静态方法

//消息提示(context,"内容",固定时间)
Toast.makeText(DraperyActivity.this,"ListenActivity",Toast.LENGTH_LONG).show();

2.构造Toast方法_01

自定义消息提示

//构造toast显示 01
toast_01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//构造toast
Toast toast = new Toast(DraperyActivity.this);
//new一个ImageView
ImageView imageView = new ImageView(DraperyActivity.this);
//设置img
imageView.setImageResource(R.mipmap.qq);
toast.setView(imageView);
//设置显示时长
toast.setDuration(Toast.LENGTH_SHORT);
//展现
toast.show();
}
});

3.构造Toast方法_02(自定义提示)

这里需要设置一个新的activity当作消息提示的内容使用

activity_toastviwe.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
> <ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/qq" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这里是构造toast显示" /> </LinearLayout>

函数方法:

//构造toast显示 02
toast_02.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//1.创建一个view,用inflate去解析一个xml文件
View toastview = LayoutInflater.from(DraperyActivity.this).inflate(R.layout.activity_toastviwe,null);
//2.构造(上下文)
Toast toast = new Toast(DraperyActivity.this);
//3.设置属性
toast.setView(toastview);
//set显示时间
toast.setDuration(Toast.LENGTH_SHORT);
//set展现的位置
toast.setGravity(Gravity.CENTER_HORIZONTAL,0,0);
toast.show();
}
});

4.dialog消息提示

需要用户做出响应,一般用于严重的警告,公告什么的.....

通过android.app.AlertDialog.Builder类来建立,在建立的过程中可以进行多项设置。

setlcon()和setTitle(); 用于设置图标和标题;

用于设置提示信息;setMessage() :

用于设置左、中、右按钮 setPositiveButton()、setNeutralButton()和setNegativeButton()

 //dialog消息提示
public void dialog01(View view){
switch (view.getId()){
case R.id.dialog_01:
AlertDialog dialog = new AlertDialog.Builder(DraperyActivity.this)
//设置图片
.setIcon(R.mipmap.qq)
//设置标题
.setTitle("Test")
//右边的按钮
.setPositiveButton("右", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(DraperyActivity.this,"你点击了右",Toast.LENGTH_SHORT).show();
}
})
//中间的按钮
.setNegativeButton("中",null)
//左边的按钮 .setNeutralButton("左", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(DraperyActivity.this,"你点击了左",Toast.LENGTH_SHORT).show();
}
})
.setMessage("这里是dialog消息提示框")
.create(); dialog.show();
break;
}
}

Android基础------高级ul:消息提示的更多相关文章

  1. Android基础------高级ul:消息对话框

    前言:Android消息对话框提示笔记,刚刚接触Android 1.经典模式 //列表对话框 //经典模式 public void listdialog_01(View view){ final St ...

  2. Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)

    Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...

  3. android学习笔记21——消息提示Toast

    消息提示可细分为两种:大量消息提示——当程序有大量图片.信息需要展示时,采用对话框消息提示: 小量消息提示——当程序只有少量信息需要呈现给用户时,采用轻量级的对话框——Toast; Toast ==& ...

  4. Android:Toast简单消息提示框

    Toast是简单的消息提示框,一定时间后自动消失,没有焦点. 1.简单文本提示的方法: Toast.makeText(this, "默认的toast", Toast.LENGTH_ ...

  5. Android三种消息提示

    Android消息提示有三种方式: 1  使用Toast显示消息提示框 Toast类用于在屏幕中显示一个提示信息框,该消息提示框没有任何控制按钮,并且不会获得焦点,经过一定时间后自动消失.通常用于显示 ...

  6. 【Android代码片段之六】Toast工具类(实现带图片的Toast消息提示)

    转载请注明出处,原文网址:http://blog.csdn.net/m_changgong/article/details/6841266  作者:张燕广 实现的Toast工具类ToastUtil封装 ...

  7. 10. Android框架和工具之 AppMsg(消息提示)

    1. AppMsg 优雅的弹出类似Toast的消息提示,支持3种状态Alert(警告),Confirm(确认)以及Info(消息).        2. AppMsg使用: (1)AppMsg下载地址 ...

  8. Android应用开发学习之Toast消息提示框

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来看Toast消息提示框的用法.使用Toast消息提示框一般有三个步骤: 1.  创建一个Toast对象.可 ...

  9. 第13讲- Android之消息提示Notification

    第13讲 Android之消息提示Notification .Notification Notification可以理解为通知的意思一般用来显示广播信息,通知可以显示到系统的上方的状态栏(status ...

随机推荐

  1. ubuntu 杂记

    修改/home下中文目录 网易云sudo解决 https://jingyan.baidu.com/article/1e5468f956a15c484861b770.html 字体     https: ...

  2. Leecode刷题之旅-C语言/python-217存在重复元素

    /* * @lc app=leetcode.cn id=217 lang=c * * [217] 存在重复元素 * * https://leetcode-cn.com/problems/contain ...

  3. [Cracking the Coding Interview] 4.1 Route Between Nodes 节点间的路径

    Given a directed graph, design an algorithm to find out whether there is a route between nodes. 这道题让 ...

  4. 成都Uber优步司机奖励政策(1月10日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  5. 「题目代码」P1039~P1043(Java)

    P1039 谭浩强C语言(第三版)习题4.9 import java.util.*; import java.io.*; import java.math.BigInteger; public cla ...

  6. hdu2509Be the Winner(反nim博弈)

    Be the Winner Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  7. Appium_Python_API说明

    Appium_Python_API 1.contexts contexts(self): Returns the contexts within the current session. 返回当前会话 ...

  8. myeclipse tomcat部署按钮点击没反应

    进入workspace目录,删除.metadata\.plugins\org.eclipse.core.runtime\.settings\com.genuitec.eclipse.ast.deplo ...

  9. Siki_Unity_1-6_C#编程初级教程(未学)

    Unity 1-6 C#编程初级教程 任务1:C#和.Net框架 C#是.Net里的一个成分 2002年微软发布第一个.Net框架(多平台,行业标准,安全性) .Net框架 IDE编程工具 --产生- ...

  10. 本地矩阵(Local Matrix)

    本地矩阵具有整型的行.列索引值和双精度浮点型的元素值,它存储在单机上.MLlib支持稠密矩阵DenseMatrix和稀疏矩阵Sparse Matrix两种本地矩阵,稠密矩阵将所有元素的值存储在一个列优 ...