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

  • Felice Musique

    Felice Musiq

    22 NİSAN 2014
  • george sarintzotis

    george sarin

    2 Aralık 2007
  • Google Developers

    Google Devel

    23 AĞUSTOS 2007