android自定义风格的toast
先上图看一下我的自定义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的更多相关文章
- ToastCustom【自定义显示风格的Toast】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 基于系统Toast的自定义显示风格的Toast. 效果图 代码分析 ToastCustom类基于系统Toast,不是继承Toast, ...
- Android之styles.xml,以及自定义风格
1.styles.xml 在现在的ADT创建的Project中,会有values,values-v11和values-v14三个文件夹,每个文件夹下都有一个styles.xml. API11是Andr ...
- Android 自定义View合集
自定义控件学习 https://github.com/GcsSloop/AndroidNote/tree/master/CustomView 小良自定义控件合集 https://github.com/ ...
- Android 自定义ScrollView ListView 体验各种纵向滑动的需求
分类: [android 进阶之路]2014-08-31 12:59 6190人阅读 评论(10) 收藏 举报 Android自定义ScrollView纵向拖动 转载请标明出处:http: ...
- 几种不同风格的Toast
一般情况下,我们使用Toast默认的风格就行了,只是有些时候为了达到我们自己想要的效果需要自定义一下,包括自定义显示的位置,显示的内容以及完全自定义里面的布局,代码如下: activity: pack ...
- Android自定义实现微信标题栏
Android自定义实现微信标题栏 前言:在android的开发中有时我们需要更个性化的标题栏,而不仅仅是系统预定义的图标加软件名,同时有时候我们需要在标题栏中实现更多功能,如添加按钮响应用户 ...
- 显示图片的(自定义)吐司Toast
一般我们提示的时候都是直接提示文字的,其实Toast也可以显示图片 常用方法 Toast.makeText(context,text,duration)这返回一个Toast对象 toast.setDu ...
- 【转载】Android Metro风格的Launcher开发系列第二篇
前言: 各位小伙伴们请原谅我隔了这么久才开始写这一系列的第二篇博客,没办法忙新产品发布,好了废话不说了,先回顾一下:在我的上一篇博客Android Metro风格的Launcher开发系列第一篇写了如 ...
- Android 自定义title 之Action Bar
Android 自定义title 之Action Bar 2014-06-29 飞鹰飞龙... 摘自 博客园 阅 10519 转 25 转藏到我的图书馆 微信分享: Action Ba ...
随机推荐
- 安装redis出现的问题
这个问题是我在腾讯云上安装redis时出现的错误, 1.在执行make命令时出现的错误 解决方案,没有安装gcc 什么是gcc: GCC是一个用于linux系统下编程的编译器是一个用于编程开发的自由编 ...
- PMP 考试 形式
200 道单选题- 考试时间为4个小时(上午9点到下午1点) 1年4次考试时间 2017年 3月18 6月24 9月9 10月9 考试费用3300 PMBOK
- CAB归档文件提取工具cabextract
CAB归档文件提取工具cabextract 在对Windows系统进行数字取证中,经常会遇到.cab的文件.该文件是Windows的压缩格式,一般是作为安装包文件.Kali Linux预置了专用的 ...
- HDU.4035.Maze(期望DP)
题目链接 (直接)设\(F(i)\)为在\(i\)点走出迷宫的期望步数.答案就是\(F(1)\). 令\(p_i=1-k_i-e_i\),表示\(i\)点沿着边走的概率:\(d_i=dgr[i]\), ...
- 菜鸟nginx源码剖析
菜鸟nginx源码剖析 配置与部署篇(一) 手把手配置nginx "I love you" TCMalloc 对MYSQL 性能 优化的分析 菜鸟nginx源码剖析系列文章解读 A ...
- Codeforces Round #374 (Div. 2) C. Journey DP
C. Journey 题目连接: http://codeforces.com/contest/721/problem/C Description Recently Irina arrived to o ...
- 研究table-cell和overflow
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Tomcat无法启动8005端口,提示:java.net.ConnectException: 拒绝连接 (Connection refused)
修改$JAVA_HOME/jre/lib/security/Java.security 文件中 securerandom.source 配置项: 将 securerandom.source=file: ...
- 鸟哥的Linux私房菜 基础学习篇读书笔记(9):Linux磁盘与文件系统管理(2)
上一篇文章主要从理论上分析了Linux的Ext2文件系统.这一篇主要解说怎样查看Linux的文件系统的容量以及解说Linux文件系统中的连接文件. 能够通过df和du命令来查看磁盘与文件夹的容量.df ...
- ChromeDriver启动Chrome浏览器后,地址栏只显示data;——chromeDriver版本不对
ChromeDriver启动Chrome浏览器后,地址栏只显示data; 错误原因: chromeDriver版本不对,不同版本的chromeDriver对应不同版本的chrome浏览器 chrome ...