先上图看一下我的自定义toast的样式

源码下载地址:

CustomToastActivity.java源码

package com.jinhoward.ui_customtoast;
/**
* Author :jinhoward
* Date:2013-07-21
* Funtion: A toast of custom style.
*/ import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast; public class CustomToastActivity extends Activity {
private Button button; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_toast); button=(Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {
// TODO Auto-generated method stub LayoutInflater inflater = getLayoutInflater();
View customLayoutView = inflater.inflate(R.layout.toast_layout,
null); Toast toast = new Toast(getApplicationContext()); //设置toast为垂直居中显示
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(customLayoutView);
toast.show(); }
}); }
}

activity_custom_toast.xml源码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#D1EEEE"> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_gravity="center"
android:text="显示自定义的Toast" /> </LinearLayout>

toast_layout.xml源码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#DAAAAA"
android:orientation="horizontal"
android:padding="8dp" > <ImageView
android:id="@+id/ImageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/lock" /> <TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="10sp"
android:gravity="top|left|center"
android:layout_toRightOf="@+id/ImageView1"
android:textStyle="bold"
android:text="这是一个自定义的toast!"
android:textColor="#FF0000" /> </RelativeLayout>

android自定义风格的toast的更多相关文章

  1. ToastCustom【自定义显示风格的Toast】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 基于系统Toast的自定义显示风格的Toast. 效果图 代码分析 ToastCustom类基于系统Toast,不是继承Toast, ...

  2. Android之styles.xml,以及自定义风格

    1.styles.xml 在现在的ADT创建的Project中,会有values,values-v11和values-v14三个文件夹,每个文件夹下都有一个styles.xml. API11是Andr ...

  3. Android 自定义View合集

    自定义控件学习 https://github.com/GcsSloop/AndroidNote/tree/master/CustomView 小良自定义控件合集 https://github.com/ ...

  4. Android 自定义ScrollView ListView 体验各种纵向滑动的需求

      分类: [android 进阶之路]2014-08-31 12:59 6190人阅读 评论(10) 收藏 举报 Android自定义ScrollView纵向拖动     转载请标明出处:http: ...

  5. 几种不同风格的Toast

    一般情况下,我们使用Toast默认的风格就行了,只是有些时候为了达到我们自己想要的效果需要自定义一下,包括自定义显示的位置,显示的内容以及完全自定义里面的布局,代码如下: activity: pack ...

  6. Android自定义实现微信标题栏

    Android自定义实现微信标题栏     前言:在android的开发中有时我们需要更个性化的标题栏,而不仅仅是系统预定义的图标加软件名,同时有时候我们需要在标题栏中实现更多功能,如添加按钮响应用户 ...

  7. 显示图片的(自定义)吐司Toast

    一般我们提示的时候都是直接提示文字的,其实Toast也可以显示图片 常用方法 Toast.makeText(context,text,duration)这返回一个Toast对象 toast.setDu ...

  8. 【转载】Android Metro风格的Launcher开发系列第二篇

    前言: 各位小伙伴们请原谅我隔了这么久才开始写这一系列的第二篇博客,没办法忙新产品发布,好了废话不说了,先回顾一下:在我的上一篇博客Android Metro风格的Launcher开发系列第一篇写了如 ...

  9. Android 自定义title 之Action Bar

    Android 自定义title 之Action Bar 2014-06-29  飞鹰飞龙...  摘自 博客园  阅 10519  转 25 转藏到我的图书馆   微信分享:   Action Ba ...

随机推荐

  1. Orleans入门

    一.Grains 二.开发一个Grain 三.开发一个客户端 四.运行应用程序 五.调式 一.Grains Grains是Orleans编程模型的关键原语. Grains是Orleans应用程序的构建 ...

  2. 基于图文界面的蓝牙扫描工具btscanner

    基于图文界面的蓝牙扫描工具btscanner   btscanner是Kali Linux内置的一款蓝牙扫描工具.它提供图文界面,更便于渗透测试人员查看扫描信息.该工具会自动使用主机所有的蓝牙接口,并 ...

  3. android 多进程

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha android应用中 可以通过 清单文件的属性配置,创建出一个新进程. 多进程的好处,当 ...

  4. mybatis学习笔记(六) -- maven+spring+mybatis从零开始搭建整合详细过程(下)

    继续 mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上) 五.使用监听器启动Spring容器 1.修改pom.xml文件,添加Spring-we ...

  5. java php c# 三种语言的AES加密互转

    java php c# 三种语言的AES加密互转 最近做的项目中有一个领取优惠券的功能,项目是用php写得,不得不佩服,php自带的方法简洁而又方便好用.项目是为平台为其他公司发放优惠券,结果很囧的是 ...

  6. KVM磁盘镜像qcow2、raw、vmdk等格式区别(转)

    raw(default) the raw format is a plain binary image of the disc image, and is very portable. On file ...

  7. TCP状态知识总结(图解)

    tcp状态:   LISTEN:侦听来自远方的TCP端口的连接请求 SYN-SENT:再发送连接请求后等待匹配的连接请求 SYN-RECEIVED:再收到和发送一个连接请求后等待对方对连接请求的确认 ...

  8. LOG EXPLORER ApexSQL Log

    http://www.minisoft.cn/ https://www.apexsql.com/sql_tools_log.aspx

  9. 项目内部IT/电商/信息化类简报,分享电子版

    除了一些国内不准发的内容,还有公司内部项目相关的.其他的大多数资料会在微信公众号推送,分享一下吧,希望大家也能推荐一些好文章. 微信公众号:WallinWind,原创IT类文章在CSDN博客也会同步更 ...

  10. CRM上线之路 走上了CRM实施顾问-第12天上班 -第三周

    今天是周五,<CRM初期需求说明>是经理们商讨的,总共2张纸,根据两次会议,我写了<CRM需求说明>总共18面. 这是这周的工作汇报,其实,报告是我一天内写出来的,中午饭都没吃 ...