[android自定义控件]带有图片的Toast

        作者:sundroid

       个人站点:sundroid.cn    邮箱: hfutsnjc@163.com   微博:http://weibo.com/Sundroid

本文源码(utf-8编码):http://download.csdn.net/detail/hfut11/7899469

效果图

主要控制代码


	@Override
	public void onClick(View arg0) {
		LayoutInflater inflater = getLayoutInflater();
		View view = inflater.inflate(R.layout.custom_toast,
				(ViewGroup) findViewById(R.id.toast_layout));
		view.findViewById(R.id.txt_Title);
		view.findViewById(R.id.txt_context);
		view.findViewById(R.id.image_toast);
		toast = new Toast(getApplicationContext());
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setView(view);
		toast.show();
	}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/toast_layout"
  android:orientation="vertical"
  android:background="#111111"
  android:layout_width="200dip"
  android:layout_height="fill_parent">
  	<TextView
  		android:id="@+id/txt_Title"
  		android:layout_gravity="center|top"
  		android:text="@string/toast_text_1"
  		android:layout_width="wrap_content"
  		android:layout_height="wrap_content"
  		android:textColor="#ffffff"
  		android:textSize="20dip"
  	></TextView>
  	<LinearLayout
  		android:orientation="horizontal"
  		android:layout_width="wrap_content"
  		android:layout_height="wrap_content"
  		android:background="#999999">
  		<ImageView
	  		android:id="@+id/image_toast"
	  		android:src="@drawable/wallpaper_field_small"
	  		android:layout_width="wrap_content"
	  		android:layout_height="wrap_content"
	  		android:layout_marginRight="10dip"
  		></ImageView>
  		<TextView
  			android:id="@+id/txt_context"
  			android:textColor="#ffffff"
  			android:layout_gravity="center|right"
  			android:text="@string/toast_text_2"
  			android:textSize="15dip"
	  		android:layout_width="wrap_content"
	  		android:layout_height="wrap_content"
  		></TextView>
  	</LinearLayout>
</LinearLayout>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值