-
<?xml version="1.0" encoding="utf-8"?>
-
<selector xmlns:android="http://schemas.android.com/apk/res/android">
-
<item android:state_focused="false" android:state_pressed="true"
-
android:drawable="@drawable/button_on" />
-
<item android:drawable="@drawable/button_off" />
-
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/button_on" />
<item android:drawable="@drawable/button_off" />
</selector>
이제 버튼 컨트롤의 background 속성에 저 XML파일의 id값을 지정해 주면 됩니다.
-
Button btn = new Button(getApplicationContext());
-
btn.setBackgroundDrawable(R.drawable.button_bg);
위와 같은 방법으로 하려면
버튼마다 Selector xml파일이 존재하여야 하는데..
현재 롤오버를 적용해야 할 버튼이 20개입니다.
그럼 위와 같은 방식으로 xml파일을 20개 만들어서 적용하는 방법밖에 없는건가요?