- 浏览: 506438 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (422)
- 重要 (12)
- BUG解决备忘录 (32)
- 环境搭建 (17)
- 开源组件 (4)
- 数据库 (16)
- 设计模式 (4)
- 测试 (3)
- javascript (5)
- Android (14)
- jdk相关 (9)
- struts2 (10)
- freemark (3)
- 自定义扩展及工具类 (5)
- jdk5新特性及java基础 (13)
- ssh及其他框架 (15)
- linux (32)
- tcp-ip http协议 (8)
- 服务器集群与负载均衡 (34)
- 项目管理相关 (11)
- 实用小技术 (10)
- 架构相关 (14)
- firefox组件 (11)
- spider (6)
- 产品设计 (11)
- PHP (1)
- ws (4)
- lucene (10)
- 其他 (2)
- BI (1)
- NoSQL (3)
- gzip (1)
- ext (4)
- db (6)
- socket (1)
- 源码阅读 (2)
- NIO (2)
- 图片处理 (1)
- java 环境 (2)
- 项目管理 (4)
- 从程序员到项目经理(一):没有捷径 (1)
- bug (1)
- JAVA BASE (8)
- 技术原理 (0)
- 新框架新技术 (1)
- 量化与python (1)
- 系统编程 (0)
- C语言 (0)
- 汇编 (0)
- 算法 (0)
最新评论
-
hyspace:
别逗了,最后一个算法根本不是最优的,sort(function ...
数组去重——一道前端校招试题 -
washingtin:
楼主能把策略和路由的类代码贴出来吗
Spring + iBatis 的多库横向切分简易解决思路 -
sdyjmc:
初略看了一下,没有闹明白啊,均衡负载使用Nginx,sessi ...
J2EE集群原理 I -
shandeai520:
谢谢大神!请教大神一个问题:假如我有三台服务器,连接池的上限是 ...
集群和数据库负载均衡的研究 -
hekuilove:
给lz推荐一下apache commonsStringUtil ...
request 获取 ip
Toast用于向用户显示一些帮助/提示。下面我做了5中效果,来说明Toast的强大,定义一个属于你自己的Toast。
注意:
LENGTH_LONG---长时间显示视图或文本提示
LENGTH_SHORT---短时间显示视图或文本提示
setGravity(int gravity,int xOffset,int yOffset)---设置提示应该在屏幕上的显示的位置
setDuration(int duartion)---设置提示显示的持续时间
1.默认效果
代码
Toast.makeText(getApplicationContext(), "默认Toast样式",
Toast.LENGTH_SHORT).show();
2.自定义显示位置效果
代码
toast = Toast.makeText(getApplicationContext(),
"自定义位置Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
3.带图片效果
代码
toast = Toast.makeText(getApplicationContext(),
"带图片的Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout) toast.getView();
ImageView imageCodeProject = new ImageView(getApplicationContext());
imageCodeProject.setImageResource(R.drawable.icon);
toastView.addView(imageCodeProject, 0);
toast.show();
4.完全自定义效果
代码
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom,
(ViewGroup) findViewById(R.id.llToast));
ImageView image = (ImageView) layout
.findViewById(R.id.tvImageToast);
image.setImageResource(R.drawable.icon);
TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);
title.setText("Attention");
TextView text = (TextView) layout.findViewById(R.id.tvTextToast);
text.setText("完全自定义Toast");
toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
5.其他线程
代码
new Thread(new Runnable() {
public void run() {
showToast();
}
}).start();
完整代码
1.Main,java
package com.wjq.toast;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Main extends Activity implements OnClickListener {
Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.btnSimpleToast).setOnClickListener(this);
findViewById(R.id.btnSimpleToastWithCustomPosition).setOnClickListener(
this);
findViewById(R.id.btnSimpleToastWithImage).setOnClickListener(this);
findViewById(R.id.btnCustomToast).setOnClickListener(this);
findViewById(R.id.btnRunToastFromOtherThread).setOnClickListener(this);
}
public void showToast() {
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "我来自其他线程!",
Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onClick(View v) {
Toast toast = null;
switch (v.getId()) {
case R.id.btnSimpleToast:
Toast.makeText(getApplicationContext(), "默认Toast样式",
Toast.LENGTH_SHORT).show();
break;
case R.id.btnSimpleToastWithCustomPosition:
toast = Toast.makeText(getApplicationContext(),
"自定义位置Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
break;
case R.id.btnSimpleToastWithImage:
toast = Toast.makeText(getApplicationContext(),
"带图片的Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout) toast.getView();
ImageView imageCodeProject = new ImageView(getApplicationContext());
imageCodeProject.setImageResource(R.drawable.icon);
toastView.addView(imageCodeProject, 0);
toast.show();
break;
case R.id.btnCustomToast:
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom,
(ViewGroup) findViewById(R.id.llToast));
ImageView image = (ImageView) layout
.findViewById(R.id.tvImageToast);
image.setImageResource(R.drawable.icon);
TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);
title.setText("Attention");
TextView text = (TextView) layout.findViewById(R.id.tvTextToast);
text.setText("完全自定义Toast");
toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
break;
case R.id.btnRunToastFromOtherThread:
new Thread(new Runnable() {
public void run() {
showToast();
}
}).start();
break;
}
}
}
2.main,xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="5dip" android:gravity="center">
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/btnSimpleToast"
android:text="默认"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="自定义显示位置"
android:id="@+id/btnSimpleToastWithCustomPosition"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/btnSimpleToastWithImage"
android:text="带图片"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="完全自定义"
android:id="@+id/btnCustomToast"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="其他线程"
android:id="@+id/btnRunToastFromOtherThread"></Button>
</LinearLayout>
3.custom.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffffff" android:orientation="vertical"
android:id="@+id/llToast" >
<TextView
android:layout_height="wrap_content"
android:layout_margin="1dip"
android:textColor="#ffffffff"
android:layout_width="fill_parent"
android:gravity="center"
android:background="#bb000000"
android:id="@+id/tvTitleToast" />
<LinearLayout
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/llToastContent"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:layout_marginBottom="1dip"
android:layout_width="wrap_content"
android:padding="15dip"
android:background="#44000000" >
<ImageView
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:id="@+id/tvImageToast" />
<TextView
android:layout_height="wrap_content"
android:paddingRight="10dip"
android:paddingLeft="10dip"
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#ff000000"
android:id="@+id/tvTextToast" />
</LinearLayout>
</LinearLayout>
发表评论
-
Android源码去除锁屏及应用程序开机自动运行不锁屏全屏显示
2012-12-01 04:11 2117针对RealV210提供的源码 android_gingerb ... -
三步搞定android应用图片缓存
2012-08-27 13:56 728目前很多商业应用都会涉及到从网络上读取图片数据的问题,为了节约 ... -
关于BitmapFactory.decodeStream(is)方法无法正常解码为Bitmap对象的解决方法
2012-08-27 01:22 0分类: Android开发技术 2011-08-08 19:0 ... -
Android 菜单(OptionMenu)大全 建立你自己的菜单
2012-08-20 00:13 863菜单是用户界面中最常见的元素之一,使用非常频繁,在Andro ... -
android 全屏问题
2012-08-08 13:40 789<supports-screens android:la ... -
android 开发中中,经常用到的代码(转载)
2012-08-08 13:32 1613android 开发中中,经常用到的代码(转载) 2012-0 ... -
控制Android系统 全屏并且 程序开机自动运行 并且实现程序运行中 开机不锁屏
2012-08-08 12:06 0首先实现程序开机自动运行 需要 捕获系统的广播android. ... -
Android Socket网络通信
2011-11-04 16:53 13051.服务器程序: Java代码 p ... -
Android 开发环境搭建中--- “An SDK Target must be specified.” 问题解决
2010-08-31 02:22 1094问题描述: 按照网络上的文档,搭 ... -
Android学习笔记(6)——Android——LoginDemo
2010-08-31 00:55 1201在这个demo中,将涉及到Activity(活动)的交互— ... -
Android学习笔记(5)——Android——HelloWorldDemo
2010-08-31 00:54 1204工程目录结构: HelloWorldActi ... -
Android学习笔记(4)——Android Application是如何运行的
2010-08-31 00:53 2224任何Android应用程序都是由以下4个部分中的必要组合而 ... -
Android学习笔记(3)——Android Demo演示
2010-08-31 00:51 1085第一步,启动Eclipse,File->New-&g ... -
Android学习笔记(2)——搭建Android开发平台
2010-08-31 00:50 1456Eclipse+Android SDK 一、下载Ecl ... -
Android学习笔记(1)——什么是Android
2010-08-31 00:49 749Android 是Google开发的基于Linux平台的开源手 ...
相关推荐
•Android---UI篇---Toast(提示) • •Android---UI篇---Button(按钮) • •Android---UI篇---TextView(文本框) • •Android---UI篇---EditText(编辑框) • •Android---UI篇---DatePicker,TimePicker(日期...
用于React的TOAST UI日历这是一个包装的React组件。 :triangular_flag: 目录事件拉取请求步骤文件资料贡献执照 收集有关使用开源的统计信息TOAST UI Calendar的React Wrapper应用Google Analytics(分析)(GA)来...
Vue的TOAST UI日历这是包装TOAST UI日历的Vue组件。 :triangular_flag:目录收集有关开源使用情况的统计信息。安装VAST的TOAST UI日历这是包装TOAST UI日历的Vue组件。 目录收集有关使用开源的统计信息安装使用npm...
npm install muse-ui-toast -S // or yarn add muse-ui-toast CDN < link rel =" stylesheet " href =" https://unpkg.com/muse-ui-loading/dist/muse-ui-toast.all.css "/> < script src =" ...
Notice注意:不建议使用此存储库TOAST UI Editor Vue Wrapper已与TOAST UI Editor存储库分开进行管理。 结果:warning:注意:不赞成使用此存储库TOAST UI Editor Vue Wrapper已与TOAST UI Editor存储库分开进行管理。...
用于React的TOAST UI图像编辑器 这是一个包装的React组件。 :triangular_flag: 目录 收集有关使用开源的统计信息 TOAST UI图像编辑器的React Wrapper应用Google Analytics(分析)(GA)来收集有关开源使用情况的...
Notice注意:不建议使用此存储库TOAST UI Grid Vue Wrapper已与TOAST UI Grid存储库分开进行管理。 :warning:通知的结果:不建议使用此存储库TOAST UI Grid Vue Wrapper已与TOAST UI Grid存储库分开进行管理。 由于...
Android Toast 工具类
bootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toastbootstrap-toast 的消息提示toast
自定义toast提示,可设置,做了封装
Vue的TOAST UI图表这是包装TOAST UI图表的Vue组件。 :triangular_flag:目录收集有关开源使用情况的统计信息使用VAST的TOAST UI Chart安装这是包装TOAST UI Chart的Vue组件。 :triangular_flag:目录收集有关使用开源...
课堂资源代码(Android-Toast 控件使用)
react-native-simple-toast, 简单的Toast React react-native-simple-toast对安卓和iOS的本机Toast组件进行反应。 它让iOS拥有与安卓相同的toast性能。 使用 scalessec/toast iOS ;安装你可以使用 rnpm插件轻松安装...
toast的基本封装,包括单例化,成功和失败的提示吐司
----------------------- 实验1--Android基础入门与Android-UI开发应用(1)全文共3页,当前为第1页。 实验1--Android基础入门与Android-UI开发应用(1)全文共3页,当前为第2页。 实验1--Android基础入门与Android-UI...
React Native Toast 一个用于android和ios类似于android toast提示控件,android使用原生toast, ios使用UIView Toast
Android:实现Toast自定义样式(包括:自定义位置、带图片等)、自定义显示时长(包括可用系统时长、可自定义)
命令式API 键盘感知灵活的配置安装yarn add react-native-toast-message用法在应用程序入口文件中渲染Toast组件(以及在那里可能呈现的所有内容),并为其设置引用。 // App.jsximport Toast from 'react-native-...
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',...
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