티스토리 뷰

Android/Android Studio

이미지 버튼

Dev-Drake 2019. 4. 4. 17:42
반응형

// main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ImageButton
 android:id="@+id/ImgBtn"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src = "@drawable/icon"
    android:text="@string/hello"
    />
</LinearLayout>

 

// ImgButton.java

package pkg.ImgButton;

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

public class ImgButton extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ImageButton imgbtn = (ImageButton)findViewById(R.id.ImgBtn);
        imgbtn.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(ImgButton.this, "Image Button Clicked", Toast.LENGTH_SHORT).show();
   }
  });
    }
}

 

반응형

'Android > Android Studio' 카테고리의 다른 글

동그란 Progress  (0) 2019.04.04
파일 입출력  (0) 2019.04.04
내부 스레드 & 핸들러  (0) 2019.04.04
외부 스레드 & 핸들러  (0) 2019.04.04
메모 - 데이터 베이스 사용  (0) 2019.04.04
댓글
반응형
최근에 올라온 글
Total
Today
Yesterday