首页 > 移动平台 > 详细

android 自定义toast width height 背景图片

时间:2015-02-04 18:44:35      阅读:328      评论:0      收藏:0      [点我收藏+]

Android 自定义toast 宽高大小 背景图片


 RelativeLayout layout = (RelativeLayout) getLayoutInflater().inflate(R.layout.layout_custom_toast,null);
        ((TextView) layout.findViewById(R.id.tvCheckoutWay)).setText("11111");
        ((TextView) layout.findViewById(R.id.tvPercent)).setText("22222");
        Toast toast = new Toast(getApplicationContext());
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.BOTTOM, 0,(int)getResources().getDimension(R.dimen.spacing_4));
        toast.setView(layout);//setting the view of custom toast layout
        toast.show();

layout.xml


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

    <LinearLayout
        style="@style/style_base"
        android:layout_width="200dp"
        android:layout_height="48dp"
        android:background="@drawable/bg_toast_data"
        android:gravity="center"
       >

        <TextView
            android:id="@+id/tvCheckoutWay"
           android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="AAAA" />

        <TextView
            android:id="@+id/tvPercent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="{100%}"
            android:textColor="@color/green_deep"
            android:textSize="@dimen/text_size_menu" />
    </LinearLayout>
</RelativeLayout>

需要注意的是最外一层layout不要放背景图片,不然怎么都改变不了大小和宽高,要改只能在中间这层再改



图片

技术分享

android 自定义toast width height 背景图片

原文:http://blog.csdn.net/zabio/article/details/43488411

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!