1. 투명 PNG 파일 만들기 를 먼저해야한다.
https://pixlr.com/editor/ 이 싸이트를 이용한다.
사용방법은 http://belitino.tistory.com/96 참고~
2. Button을 상속받은 비트맵 버튼을 만든다. (이미지 버튼은 좀 이상한듯)
package com.company.mybitmapbutton;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Button;
/**
* Created by brad on 2015-09-14.
*/
public class MyBitmapButton extends Button {
private int normalButton = 0;
private int clickedButton = 0;
public MyBitmapButton(Context context) {
super(context);
}
public MyBitmapButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setImage(int normalImg, int clickedImg) {
this.normalButton = normalImg;
this.clickedButton = clickedImg;
super.setBackgroundResource(normalButton);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
setBackgroundResource(clickedButton);
}else if(action == MotionEvent.ACTION_UP){
setBackgroundResource(normalButton);
}
return true;
}
}
3. 아래처럼 가져다가 사용한다.
plusButton = (MyBitmapButton) findViewById(R.id.button);
minusButton = (MyBitmapButton) findViewById(R.id.button2);
onOff = (MyBitmapButton) findViewById(R.id.button3);
plusButton.setImage(R.drawable.plus, R.drawable.plus);
minusButton.setImage(R.drawable.minus, R.drawable.minus);
onOff.setImage(R.drawable.on, R.drawable.off);
레퍼런스:
https://www.youtube.com/watch?v=P-A2m2KuTNU&index=55&list=PLG7te9eYUi7vXZf7O6Fd2YCnJlx5YG9qq
'안드로이드' 카테고리의 다른 글
| [안드로이드 웹뷰] 웹에서 네이티브앱의 액티비티 호출하기 (0) | 2015.08.21 |
|---|---|
| [안드로이드 웹뷰] 파일 시스템으로 부터 HTML 로딩 (0) | 2015.08.21 |
| [안드로이드 웹뷰] 돌아가기 버튼 핸들링 (0) | 2015.08.21 |
| [안드로이드 웹뷰] 네비게이션 핸들링 (0) | 2015.08.21 |
| 안드로이드 제목바(타이틀바) 없애기 (0) | 2015.07.31 |