LayoutInflater - com um xml e toast |
Top Previous Next |
Tela Aqui vemos no rodapé um Toast com xml personalizado main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Toast com Inflater de um xml" /> </LinearLayout>
toast.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >
<View android:layout_width="fill_parent" android:layout_height="2dip" android:background="#FF909090" />
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Exemplo para o LayoutInflater" />
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Muito louco este Android!" />
<ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/smile1" />
<View android:layout_width="fill_parent" android:layout_height="2dip" android:background="#FF909090" />
</LinearLayout>
Java
import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.Toast;
public class ExemploImageButton extends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle);
setContentView(R.layout.main);
LayoutInflater inflate = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflate.inflate(R.layout.toast, null);
Toast toast = new Toast(this); toast.setView(view); toast.setDuration(Toast.LENGTH_LONG); toast.show(); } } |