Codice per visualizzare un Toast di Android con una immagine e vibrazione:
package com.AndroidImageToast;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class ImageToastExample extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast toast1 = new Toast(getBaseContext());
LinearLayout toastLayout = new LinearLayout(getBaseContext());
toastLayout.setOrientation(LinearLayout.HORIZONTAL);
ImageView image = new ImageView(getBaseContext());
TextView text = new TextView(getBaseContext());
image.setImageResource(R.drawable.radiazioni);
toastLayout.addView(image);
toastLayout.addView(text);
toast1.setView(toastLayout);
toast1.setGravity(Gravity.CENTER | Gravity.CENTER, 0, 0);
Vibrator v = (Vibrator) getApplicationContext()
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(300);