package com.otn.android.toast;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MyToast extends Activity implements OnClickListener {
private static final String TOASTBTN_1 = "这是默认的Toast显示";
private static final String TOASTBTN_2 = "这是自定义位置的Toast显示";
private static final String TOASTBTN_3 = "这是带图片的Toast显示";
private static final String TOASTBTN_4 = "这是完全自定义的Toast显示";
private static final String TOASTBTN_5 = "这是长时间的Toast显示";
private Button toastBtn_1, toastBtn_2, toastBtn_3, toastBtn_4, toastBtn_5;
private Toast toast = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
toastBtn_1 = (Button) findViewById(R.id.button_1);
toastBtn_2 = (Button) findViewById(R.id.button_2);
toastBtn_3 = (Button) findViewById(R.id.button_3);
toastBtn_4 = (Button) findViewById(R.id.button_4);
toastBtn_5 = (Button) findViewById(R.id.button_5);
toastBtn_1.setOnClickListener(this);
toastBtn_2.setOnClickListener(this);
toastBtn_3.setOnClickListener(this);
toastBtn_4.setOnClickListener(this);
toastBtn_5.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder builder;
AlertDialog dialog;
switch (v.getId()) {
case R.id.button_1:
toast.makeText(this, TOASTBTN_1, Toast.LENGTH_LONG).show();
break;
case R.id.button_2:
toast = Toast.makeText(getApplicationContext(), TOASTBTN_2,
Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
break;
case R.id.button_3:
toast = Toast.makeText(getApplicationContext(), TOASTBTN_3,
Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 50, -100);
LinearLayout layout = (LinearLayout) toast.getView();
ImageView image = new ImageView(getApplicationContext());
image.setImageResource(R.drawable.wallpaper_tree_small);
layout.addView(image, 0);
toast.show();
break;
case R.id.button_4:
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.userdefinedtoast,
(ViewGroup) findViewById(R.id.toast_layout));
TextView txtView_Title = (TextView) view
.findViewById(R.id.txt_Title);
TextView txtView_Context = (TextView) view
.findViewById(R.id.txt_context);
ImageView imageView = (ImageView) view
.findViewById(R.id.image_toast);
toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(view);
toast.show();
break;
case R.id.button_5:
LayoutInflater inflater1 = getLayoutInflater();
View view1 = inflater1.inflate(R.layout.userdefinedtoast,
(ViewGroup) findViewById(R.id.toast_layout));
TextView txtView_Title1 = (TextView) view1
.findViewById(R.id.txt_Title);
TextView txtView_Context1 = (TextView) view1
.findViewById(R.id.txt_context);
ImageView imageView1 = (ImageView) view1
.findViewById(R.id.image_toast);
builder = new AlertDialog.Builder(this);
builder.setView(view1);
dialog = builder.create();
dialog.show();
// toast.makeText(this, TOASTBTN_5, Toast.LENGTH_LONG).show();
// initToast();
// myToast();
break;
default:
break;
}
}
// private void myToast(){
// Timer timer = new Timer();
// timer.schedule(new TimerTask() {
// @Override
// public void run() {
// // TODO Auto-generated method stub
// initToast();
// }
// }, 10);
// }
// private void initToast(){
// toast.show();
// }
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android 五种不同的Toast效果.zip项目安卓应用源码下载Android 五种不同的Toast效果.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android 五种不同的Toast效果.zip (24个子文件)
Android 五种不同的Toast效果
Android 五种不同的Toast效果
MyToast
AndroidManifest.xml 683B
res
layout
userdefinedtoast.xml 1KB
main.xml 1KB
drawable-ldpi
icon.png 2KB
drawable-mdpi
icon.png 3KB
drawable-hdpi
wallpaper_tree_small.jpg 14KB
icon.png 4KB
wallpaper_field_small.jpg 15KB
values
strings.xml 651B
src
com
otn
android
toast
MyToast.java 4KB
bin
com
otn
android
toast
R.class 552B
MyToast.class 4KB
R$layout.class 443B
R$attr.class 349B
R$id.class 662B
R$string.class 683B
R$drawable.class 498B
classes.dex 6KB
MyToast.apk 47KB
resources.ap_ 42KB
.classpath 280B
assets
default.properties 364B
.project 843B
gen
com
otn
android
toast
R.java 2KB
共 24 条
- 1
资源评论
yxkfw
- 粉丝: 76
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 医学图像分割数据集:超声波背景下的甲状腺结节分割(包含训练集和测试集)
- 2023数学建模国赛MatheMatical-Modeling-master.zip
- 2023数学建模2023-mathematical-modeling-master.zip
- Android动画介绍-补间动画(1)
- Redis开发安装与启动的教程与代码实例.txt
- Redis Admin一个Redis管理平台,主要用于方便查看Key信息 目前支持单机Redis和Redis Cluster模式
- 真是BIM项目招标文件模板doc
- 详细介绍Spring和SpringBoot的区别
- Address book information management system
- excel图表 元素 数据分析
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功