결과화면

 

// CustomToastDemo.java

 

package com.example.hellow;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class CustomToastDemo extends Activity{
 LinearLayout linear;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.custom_toast);

  Button show = (Button)findViewById(R.id.showToast);
  
  show.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    //레이아웃 파일을 읽어서 메모리에 인스턴스를 트리구조로 전개
    LinearLayout layout = (LinearLayout)getLayoutInflater().inflate(R.layout.toast1, null);
    Toast toast = Toast.makeText(CustomToastDemo.this, "Toast!!!", Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
   }
  });
 }
}

 

 

 

 

//  custom_toast.xml

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/showToast"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Custom_Toast" />

</LinearLayout>

 

 

--------------------------------------------------------------------------------------------------

 

//  toast1.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
   
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Custon_Toast(Top, 0, 10)"
        android:layout_gravity="bottom" />

</LinearLayout>

+ Recent posts