2013-08-01 57 views
0

寻找定制举杯为:根据需要吐司的的Android定制敬酒

  1. 大小。
  2. 烤面包的颜色。
  3. 烤面包的位置。
  4. 根据需要吐司的时间(即它会出现5秒或6秒)。
+3

http://stackoverflow.com/a/16909532/1752867这里有同样的问题和答案。 – KEYSAN

+0

非常感谢你,我从这里得到了我所有的答案。 –

+0

不客气。 – KEYSAN

回答

0

创建一个自定义布局,您选择Toast loook和感觉。

custom_toast.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/custom_toast_layout_id" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFF" 
    android:orientation="horizontal" 
    android:padding="5dp" > 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_marginRight="5dp" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:textColor="#000" /> 

</LinearLayout> 

而且里面添加的onCreate下面这段代码()按钮点击

button = (Button) findViewById(R.id.buttonToast); 

      button.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 

        // get your custom_toast.xml ayout 
        LayoutInflater inflater = getLayoutInflater(); 

        View layout = inflater.inflate(R.layout.custom_toast, 
         (ViewGroup) findViewById(R.id.custom_toast_layout_id)); 

        // set a dummy image 
        ImageView image = (ImageView) layout.findViewById(R.id.image); 
        image.setImageResource(R.drawable.ic_launcher); 

        // set a message 
        TextView text = (TextView) layout.findViewById(R.id.text); 
        text.setText("Button is clicked!"); 

        // Toast... 
        Toast toast = new Toast(getApplicationContext()); 
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); 
        toast.setDuration(Toast.LENGTH_LONG); 
        toast.setView(layout); 
        toast.show(); 


} 
     }); 

当你点击按钮,您将看到自定义Toast留言。

由于http://www.mkyong.com/android/android-toast-example/

+0

永远欢迎buddy.Happy Coding :) –