先上图看一下我的自定义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. [POI2013]Łuk triumfalny

    [POI2013]Łuk triumfalny 题目大意: 一棵\(n(n\le3\times10^5)\)个结点的树,一开始\(1\)号结点为黑色.\(A\)与\(B\)进行游戏,每次\(B\)能选 ...

  2. hdu 4445 37届金华赛区 D题

    题意:给一个坦克的高度,求炮弹能打中最多的数量 枚举角度,作为一名学霸虽然很快推出了公式,但是却没有考虑到,角度可以朝下的情况 #include<cstdio> #include<i ...

  3. maven -- 问题解决(四)警告Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published

    警告:Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Run ...

  4. Ural 2045. Richness of words 打表找规律

    2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...

  5. Tesseract OCR简单实用介绍

    做字符识别,不能不了解google的Tesseract-OCR,但是如何在自己的工程中使用其API倒是语焉不详,官网上倒是很详尽地也很啰嗦地介绍如何重新编译生成适合自己平台的lib和dll,经过近些天 ...

  6. Project 03- STM32F4xx PID controller

    Project 03- STM32F4xx PID controller CMSIS files from ARM provides ARM Math functions. There are als ...

  7. EF+Sqlite 动态设置连接字符串

    摘要 在做c/s项目的时候,如果使用ef+sqlite,我们不知道客户端会安装在哪里,需要动态的来设置db所在路径. 解决办法 /// <summary> /// 数据上下文 /// &l ...

  8. Modbus读写模拟量寄存器具体解释

    读可读写模拟量寄存器: 发送命令(主机向从机)格式: [设备地址] [命令号03] [起始寄存器地址高8位] [低8位] [读取的寄存器数高8位] [低8位] [CRC校验的低8位] [CRC校验的高 ...

  9. SUSE Linux – Zypper 命令示例

    來源:http://www.linuxidc.com/Linux/2014-11/109214.htm Zypper是SUSE Linux中用于安装,升级,卸载,管理仓库.进行各种包查询的命令行接口. ...

  10. ios 向sqlite数据库插入和读取图片数据

    向sqlite数据库插入和读取图片数据 (for ios) 假定数据库中存在表 test_table(name,image), 下面代码将图片文件test.png的二进制数据写到sqlite数据库: ...