设为首页 加入收藏

TOP

Android自定义Toast
2014-11-24 07:37:40 来源: 作者: 【 】 浏览:1
Tags:Android 定义 Toast

Android自定义Toast


步骤如下:


1 定义Toast的样式 toast.xml


< xml version="1.0" encoding="utf-8" >
android:id="@+id/hahahahhahah"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/black"
android:padding="6dp" >


android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:src="@drawable/android" >


android:id="@+id/toastTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="4dp"
android:text="这是标题栏"
android:textColor="@color/white"
android:textIsSelectable="true"
android:textSize="20sp" />


android:id="@+id/toastTextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:paddingBottom="4dp"
android:text="这是要显示的内容"
android:textColor="@color/white"
android:textIsSelectable="true"
android:textSize="12sp" />



2 自定义Toast,引用我们自己的布局


View contentView = (LinearLayout) LayoutInflater
.from(this).inflate(R.layout.toast, null);
Toast toast=new Toast(this);
toast.setGravity(Gravity.CENTER,0,0);
toast.setView(contentView);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();


这样就显示出刚才看到的效果了,大家可以在加入监听器等其他的内容


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android2.2以上使用HorizontalScr.. 下一篇Lua基础 generic for

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)