Android学习笔记(16)---定义自己的Toast

1、直接调用自带的Toast

Toast.makeText(context, "你设置的闹钟时间到了", Toast.LENGTH_LONG).show();

但是有时候不能满足我们想要的风格,于是...

2、下面来自定义属于自己风格的Toast

toast.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:shadowColor="#ff000000"
        android:shadowRadius="2.75"
        android:text="雷人科技有限公司"
        android:textSize="45dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:shadowColor="#ff000000"
        android:shadowRadius="2.75"
        android:textSize="45dp" />

</LinearLayout>

在代码中需要使用的地方调用:

View view = getLayoutInflater().inflate(R.layout.toast, null);
			Toast toastStart = new Toast(this);
			//public void setGravity (int gravity, int xOffset, int yOffset) 
			toastStart.setGravity(Gravity.BOTTOM, 0, 10);
			toastStart.setDuration(Toast.LENGTH_LONG);
			toastStart.setView(view);
			toastStart.show();

3、效果图


4、基于上面的例子,可以定义不同的Toast



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值