相信各位对这个Toast已经了解的差不多了,不过我们还可以定义各种各样的toast,废话不多说了,看代码
package com.loulijun.mytoasts;
import com.loulijun.toasts.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class ToastsActivity extends Activity {
private Button btn01,btn02,btn03,btn04;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn01 = (Button)findViewById(R.id.toast01);
btn02 = (Button)findViewById(R.id.toast02);
btn03 = (Button)findViewById(R.id.toast03);
btn04 = (Button)findViewById(R.id.toast04);
//默认的Toast
btn01.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
Toast toast = Toast.makeText(getApplicationContext(), "默认的Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, toast.getXOffset()/2, toast.getYOffset()/2);
toast.show();
}
});
//只有图片的Toast
btn02.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
Toast toast = new Toast(ToastsActivity.this);
toast.setDuration(Toast.LENGTH_LONG);
ImageView img = new ImageView(ToastsActivity.this);
img.setImageResource(R.drawable.yuanyuan);
toast.setView(img);
toast.show();
}
});
//带图片文字的Toast
btn03.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
Toast toast = Toast.makeText(getApplicationContext(), "有图有字的Toast", Toast.LENGTH_LONG);
LinearLayout layout = (LinearLayout)toast.getView();
ImageView img = new ImageView(getApplicationContext());
img.setImageResource(R.drawable.gao);
layout.addView(img,0);
toast.show();
}
});
//自定义Toast,自己设计布局文件
btn04.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
LayoutInflater li=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=li.inflate(R.layout.pictoast,null);
Toast toast = new Toast(ToastsActivity.this);
toast.setView(view);
toast.show();
}
});
}
}
这个是自定义的Toast的布局,你可以定义不同类型的Toast
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/gao"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="带图片文字的Toast"
/>
</LinearLayout>
- 大小: 44 KB
- 大小: 44.7 KB
- 大小: 49.5 KB
- 大小: 87.4 KB
分享到:
相关推荐
•Android---UI篇---Toast(提示) • •Android---UI篇---Button(按钮) • •Android---UI篇---TextView(文本框) • •Android---UI篇---EditText(编辑框) • •Android---UI篇---DatePicker,TimePicker(日期...
Android Toast 工具类
react-native-simple-toast, 简单的Toast React react-native-simple-toast对安卓和iOS的本机Toast组件进行反应。 它让iOS拥有与安卓相同的toast性能。 使用 scalessec/toast iOS ;安装你可以使用 rnpm插件轻松安装...
命令式API 键盘感知灵活的配置安装yarn add react-native-toast-message用法在应用程序入口文件中渲染Toast组件(以及在那里可能呈现的所有内容),并为其设置引用。 // App.jsximport Toast from 'react-native-...
react-native-root-toast, 像组件一样反应原生 toast,纯javascript解决方案 react-native-root-toast通知:- react-native-root-toast> = 2.1.0 only supports react-native> = 0.47.0, for reac
An Android Toast replacement, similar to the one seen in the GMail app. Multiple messages can be posted in succession, and each message will be shown for 5 seconds. Usage There's two ways to use the ...
React Native Toast 一个用于android和ios类似于android toast提示控件,android使用原生toast, ios使用UIView Toast
FrenchToast ...The API is error prone: Toast.makeText(context, "Important Toast", LENGTH_LONG); // Don't forget show()! FrenchToast gives you absolute control over your app Toasts. It
yarn add vue-toast-notification # npm npm install vue-toast-notification 用法 import Vue from 'vue' ; import VueToast from 'vue-toast-notification' ; // Import one of the available themes //import '...
Android:实现Toast自定义样式(包括:自定义位置、带图片等)、自定义显示时长(包括可用系统时长、可自定义)
> 博客地址:只需体验三分钟,你就会跟我一样,爱上这款Toast > 已投入公司项目多时,没有任何毛病,可胜任任何需求,点击此处下载Demo > 想了解实现原理的可以点击此链接查看:ToastUtils 源码 集成步骤 ...
一个响应本机模块,可以像Android一样显示吐司,它可以在iOS和Android上运行。 内容 安装 1. npm i react-native-easy-toast --save 或yarn add react-native-easy-toast 2. import Toast, {DURATION} from 'react-...
bootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toast
Android入门开发实例--Toast、Notification、Intent应用
用于React的TOAST UI日历这是一个包装的React组件。 :triangular_flag: 目录事件拉取请求步骤文件资料贡献执照 收集有关使用开源的统计信息TOAST UI Calendar的React Wrapper应用Google Analytics(分析)(GA)来...
Android和iOS平台通用的自定义Toast UI组件 USAGE INSTALL npm install react-native-mix-toast IMPORT import Toast, { Duration, Position } from 'react-native-mix-toast'; EXAMPLE Toast.show('This is Toast',...
课堂资源代码(Android-Toast 控件使用)
自定义Toast,解决系统Toast存在的问题
只需将属性修改成"positionClass": "toast-top-center", 代码如下//toastr提示框 toastr.options = { "closeButton": false, "debug": false, "newestOnTop": false, "progressBar": false, "positionClass...
Create Toast like tooltips, physical targets can be specified, or even points on screen. Many additional features and customizations. Just look at the samples Activities. Installation compile 'it....