- 浏览: 753071 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (139)
- 玩转Android (48)
- Android创意美工 (0)
- Android杂谈 (23)
- Android实例练习 (2)
- Android ROM研究 (5)
- Android NDK开发指南 (5)
- Android NDK (0)
- Android Tips (3)
- Windows Phone 7 (5)
- iPhone (0)
- HTML5学习室 (0)
- JAVA (9)
- SSH+ibatis (8)
- PHP (0)
- IT生活 (1)
- linux (2)
- C (4)
- C++ (1)
- web 前端 (1)
- 云计算 (0)
- 设计模式 (0)
- C# (2)
- 其他 (1)
- 数据结构 (5)
- Web开发 (10)
- 数据库 (3)
- 搜索引擎 (0)
- Go语言 (0)
最新评论
-
wi100sh:
多谢分享~
玩转Android---UI篇---ImageButton(带图标的按钮) -
zhanghaichang:
好文章的。
高性能web开发技术(一) -
yingang:
引用classes.dex.dex2jar.jar 拖入 j ...
Andorid杂谈---Apk文件的反编译 -
扶摇诺:
讲解的简明易懂,多谢啦!
玩转Android---UI篇---LinearLayout(线性布局) -
a13429921973:
更为详细的图文介绍,可参考这个http://blog.csdn ...
Android ROM研究---CyanogenMod源代码下载及编译
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>
转自:http://www.cnblogs.com/salam/archive/2010/11/10/1873654.html
发表评论
-
玩转Android---2D图形及动画---动画分析(Tween详细分析)
2011-09-26 21:59 2579在Android系统中提供了两种动画实现方式:一种是Tween ... -
玩转Android---2D图形及动画---图片处理
2011-09-26 13:08 1721在Android中很多地方都使 ... -
玩转Android--UI篇--PreferenceActivity(开启wifi和音乐等)
2011-09-01 11:57 4782本测试主要是为了测试PreferenceActivity的使用 ... -
玩转Android---2D图形及动画---Gif动画
2011-08-05 09:36 2166由于Gif本身就是动画,所以如果能够直接使用的话,会省去很多的 ... -
玩转Android---2D图形及动画---Frame动画
2011-08-01 20:53 2027Frame动画其实就是逐帧动画,用法也比Tween动画简单,只 ... -
玩转Android---2D图形及动画---Tween动画
2011-07-31 22:53 2139Android平台提供了两类动画,分别是Tween动画,和Fr ... -
玩转Android---2D图形及动画---View类使用
2011-07-30 23:39 2755由于游戏界面是由大量美工资源图片构成的,所以,在设计游戏界面的 ... -
玩转Android--组件篇---Handler的使用
2011-07-30 14:01 5309public class Handler ... -
玩转Android---UI篇---ZoomControls放大缩小图片
2011-07-27 13:03 7209ZoomControls控件是一个可以缩放但控件,效果如下图 ... -
玩转Android---组件篇---TextSwitcher
2011-07-25 09:21 2150还记得有一次淘宝的电话面试的时候问了我一个关于Android的 ... -
玩转Android---组件篇---AnalogClock,DigitalClock
2011-07-10 19:28 2880首先要说的是,这两个控件并不是经常的使用,但是如果程序需要的话 ... -
玩转Android---组件篇---SeekBar,RatingBar,Chronometer
2011-07-10 19:12 2809今天补充三个组件的使用,避免日后忘记。它们分别是 SeekB ... -
玩转Android---组件篇---Handler的使用(2)
2011-05-28 17:15 2761对于Handler来说,它和与它调用它的Activity是出于 ... -
玩转Android---组件篇---Handler的使用(1)
2011-05-28 15:37 2112在android中,有很多功能是不能放在onCreate或者o ... -
玩转Android---事件监听篇---第2篇
2011-05-27 10:30 5198事件监听篇---第二篇 下面是各种常用控件的事件监听的 ... -
玩转Android---事件监听篇---第1篇
2011-05-26 21:29 9896事件就是用户与UI界面的交互时所触发的操作。比如点击某一个按钮 ... -
玩转Android---组件篇---数据存储之SQLite
2011-04-17 17:05 8437Android中通过SQLite数据库引擎来实现结构化数据存储 ... -
玩转Android---组件篇---数据存储之File
2011-04-17 11:07 1998我们可以将一些数据直接以文件的形式保存在设备中。例如,一些文本 ... -
玩转Andorid---组件篇---数据存储之preference
2011-04-14 21:58 2258程序是数据的输入、处 ... -
玩转Android---组件篇---Broadcast Receiver(广播接收器)
2011-04-14 19:24 29255Braodcast Receiver顾名思义 ...
相关推荐
•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