自定义Android吐丝

      本人还是学习Android方面的新手,每学习一个东西,把学习过程记录下来方便以后查阅,还是挺好的。好了废话不多说.....

        看到一个带图片的Toast,的Demo觉得比较新颖,虽然很少看到有人用到项目里。但还是先研究一下:

        看了一下,主要是重新定义了一个需要的布局,然后转换成View,在设置到Toast里即可,跟我们自定义对话框一样一样的:

 

       View view = getLayoutInflater().inflate(R.layout.toast, null);
       TextView textview = (TextView) view.findViewById(R.id.textview);
       textview.setText("这里是Toast显示的\n提示信息......");
       Toast toast = new Toast(this);
       toast.setDuration(Toast.LENGTH_LONG);
       toast.setView(view);
       toast.show();


        在下面是布局这个Toast布局文件代码:

 

   

     

<?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:layout_margin="10dp"
    android:background="#555"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" />

</LinearLayout>

 

 

 

下面是效果:

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值