0
Android 용 초보자이며 다음 코드로 작업하고 있습니다. 기본 이미지 버튼을 설정하려고합니다. 클릭 할 때까지 눌렀을 때까지 켜짐 상태로 전환되었습니다. 온 상태와 관련된 팝업이 사라지도록 화면의 다른 곳에서 다시 또는 탭합니다. 다음 코드는 다음과 같습니다 자바 코드 : 여기 버튼을 켜기/끄기 상태로 설정하는 방법 (켜기/끄기 이미지)
<ImageButton
android:id="@+id/menu_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:paddingRight="8dp"
android:src="@drawable/menu_btn" />
는 XML 클래스의 menu_btn 코드입니다 :
private void setOnclickListeners(View view){
ImageButton button = (ImageButton) view.findViewById(R.id.menu_button);
button.setOnClickListener(this);
}
내가 트리거되는 등 다음과 오프 상태 코드를 연결하려는
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/menu_on"/>
<item android:state_pressed="true" android:drawable="@drawable/menu_on" />
<item android:drawable="@drawable/menu_off" />
</selector>
실마리가 어떻게됩니까? 개미 도움말 감사. 감사합니다! 저스틴
[toggleButton] (http://developer.android.com/reference/android/widget/ToggleButton.html)을 사용하는 것이 더 좋지 않습니까? – iBecar
실마리가 없습니까? 토글 버튼에 대한 코드를 편집하고 작동 방식을 보여 주시겠습니까? 고마워요! –