버튼을 길게 누르면 이미지 뷰의 이미지가 변경되고 버튼을 놓으면 이미지가 기본으로 돌아갑니다.버튼을 누르고있는 동안 이미지를 변경하는 방법 ... 버튼을 눌렀을 때 기본 설정을 표시합니다.
답변
OnFocusChangeListener (view) 메서드 &을 사용하여 OnFocusChange() 메서드를 재정의하십시오.
XML 선택기를 사용해야합니다. 원하는 상태에 관계없이 원하는 드로어 블을 지정할 수 있습니다.
워드 프로세서 현재 위치 : 당신이보기에 그릴 수를 할당 할 때 당신은 당신이에 스타일을 적용 할 각 상태에 대한 참조가있는 XML을 생성합니다
http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html는, 다음 버튼 (참조합니다 예를 들어, 특정 drawable 대신에). 이 SO 자세한 내용은 질문
당신은 ImageView
에 OnTouchListener
을 설정할 수 있으며, OnTouchListener
에 당신이 MotionEvent.ACTION_DOWN
에 표시 할 이미지를 설정할 수 있습니다 MotionEvent.ACTION_UP
에서 기존의 이미지를 되돌립니다.
이 솔루션을 사용하는 것이 가장 좋습니다! – jaibatrik
이
public class MButton extends Button {
public MButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MButton(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MButton(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
// define style
/**
* Send resource ids for normal, selected, pressed in respective order
*
* @param mImageIds
*/
public void setDrawablePressedBg(Integer... mImageIds) {
StateListDrawable bg = new StateListDrawable();
Drawable normal = this.getResources().getDrawable(mImageIds[0]);
Drawable selected = this.getResources().getDrawable(mImageIds[1]);
Drawable pressed = this.getResources().getDrawable(mImageIds[2]);
bg.addState(View.PRESSED_ENABLED_STATE_SET, pressed);
bg.addState(View.ENABLED_FOCUSED_STATE_SET, selected);
bg.addState(View.ENABLED_STATE_SET, normal);
bg.addState(View.FOCUSED_STATE_SET, selected);
bg.addState(View.EMPTY_STATE_SET, normal);
this.setBackgroundDrawable(bg);
}
// define style
public void setBackgroundPressedBg(Integer p1, Integer p2, Integer p3) {
StateListDrawable bg = new StateListDrawable();
Drawable normal = this.getResources().getDrawable(p1);
Drawable selected = this.getResources().getDrawable(p2);
Drawable pressed = this.getResources().getDrawable(p3);
bg.addState(View.PRESSED_ENABLED_STATE_SET, pressed);
bg.addState(View.ENABLED_FOCUSED_STATE_SET, selected);
bg.addState(View.ENABLED_STATE_SET, normal);
bg.addState(View.FOCUSED_STATE_SET, selected);
bg.addState(View.EMPTY_STATE_SET, normal);
this.setBackgroundDrawable(bg);
}
}
같은 사용자 정의 버튼 클래스를 만들 수 있습니다 그리고 당신이 당신의 XML 레이아웃 파일에 같이 갈 것
this.book_appointment = (MButton) this._view
.findViewById(R.id.btn_book);
this.book_appointment.setBackgroundPressedBg(R.drawable.btnnormal,
R.drawable.btnsel, R.drawable.btnsel);
당신의에서 onCreate 메소드에서 다음과 같이 사용할 수 있습니다
<com.packageName.custom.MButton
android:id="@+id/btn_book"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_time1"
android:layout_marginTop="20dp"
android:background="@drawable/bookapointment" />
- 1. 버튼을 눌렀을 때 기본 오렌지색을 변경하는 방법
- 2. 버튼을 누르고있는 동안 소리가납니다.
- 3. xaml에서 버튼을 눌렀을 때 컨트롤을 변경하는 방법
- 4. iOS 버튼을 눌렀을 때 컨트롤러를 변경하는 방법?
- 5. 버튼을 누르고있는 동안 발사체를 쏜다.
- 6. 버튼을 누르고있는 동안 문자 반복하기
- 7. 버튼을 누르고있는 동안 안드로이드 진동
- 8. WP7 눌렀을 때 배경 이미지를 변경하는 버튼을 만드는 방법
- 9. 버튼을 계속 누르고있는 동안 동작을 수행하는 방법
- 10. 버튼을 눌렀을 때 그리드의 세부 사항을 표시합니다.
- 11. 버튼을 눌렀을 때 jtextpane을 통해 데이터를 표시합니다.
- 12. 정보 버튼을 선택했을 때 기본 배경 이미지를 변경하는 방법
- 13. KIVY - Python 버튼을 누르고있는 동안 계속하기
- 14. Qt에서 버튼을 눌렀을 때 보여주기
- 15. 버튼을 눌렀을 때 이미지를 null로 설정하십시오.
- 16. RxSwift : 버튼을 누르고있는 동안 관찰 가능
- 17. 마우스 버튼을 누르고있는 동안 MouseMove 이벤트가 표시되지 않는 이유는 무엇입니까?
- 18. 버튼을 눌렀을 때 타임 라인을 반대로 재생
- 19. 루프가 아닌 키보드 버튼을 눌렀을 때 한 동작을 발생시키는 방법
- 20. 버튼을 눌렀을 때 수행되는 작업
- 21. 뒤로 버튼을 눌렀을 때 서랍을 여는 방법
- 22. 버튼을 눌렀을 때 변수 값을 변경하는 방법 (Android Studio)
- 23. 눌렀을 때 이미지 버튼을 강조 표시하는 방법
- 24. android 반복 버튼을 누르고있는 동작
- 25. 다른 버튼을 눌렀을 때 버튼을 강조 표시하는 방법
- 26. 버튼을 눌렀을 때 버튼 배열에서 나머지 버튼을 비활성화하는 방법
- 27. 버튼을 눌렀을 때 edittext를 지움
- 28. 버튼을 눌렀을 때 다른보기로 전환
- 29. 버튼을 눌렀을 때 목록보기 업데이트
- 30. 버튼을 눌렀을 때 div를 내림
button.setOnTouchListener (새 View.OnTouchListener() { \t \t \t 공공 부울 onTouch (보기 V, MotionEvent 이벤트) { \t \t \t \t 경우 (event.getAction() == MotionEvent.ACTION_DOWN) \t \t \t \t \t imageView1.setImageResource (R.drawable.alarm) \t \t \t \t 경우 (event.getAction() == MotionEvent.ACTION_UP) ,\t \t \t \t imageView1.setImageResource (R.drawable.charging_1); \t \t \t \t false; \t \t \t} \t \t}); –