SORU
27 EYLÜL 2011, Salı


Tost için resim ekleme?

Tost bir pop-up için bir resim programlı olarak eklemek mümkün mü?

CEVAP
28 EYLÜL 2011, ÇARŞAMBA


Evet, setView kullanarak tost bildirim imageview içine veya herhangi bir görünüm ekleyebilirsiniz() yöntemi, şartının olarak Tost özelleştirebilirsiniz bu yöntemi kullanarak.

Burada Tost bildirim içine şişirilmiş Özel düzen bir dosya yarattım ve sonra setView kullanarak Tost bildirim bu düzeni kullandım() yöntemi.

cust_toast_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:id="@ id/relativeLayout1"
  android:background="@android:color/white">

    <TextView
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@ id/textView1" android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="PM is here"
        android:gravity="center"
        android:textColor="@android:color/black">
    </TextView>

    <ImageView
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:src="@drawable/new_logo"
        android:layout_below="@ id/textView1"
        android:layout_margin="5dip"
        android:id="@ id/imageView1">
    </ImageView>

    <TextView
        android:id="@ id/textView2"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="This is the demo of Custom Toast Notification"
        android:gravity="center"
        android:layout_below="@ id/imageView1"
        android:textColor="@android:color/black">
    </TextView>

</RelativeLayout>

CustomToastDemoActivity.java

 LayoutInflater inflater = getLayoutInflater();
    View view = inflater.inflate(R.layout.cust_toast_layout,
                                   (ViewGroup) findViewById(R.id.relativeLayout1));

    Toast toast = new Toast(this);
    toast.setView(view);
    toast.show();

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Alan Fullmer

    Alan Fullmer

    3 EYLÜL 2010
  • theKGB65

    theKGB65

    24 Aralık 2007
  • TheTwistedFrequency

    TheTwistedFr

    26 NİSAN 2010