안드로이드 개발 질문/답변
(글 수 45,052)
Button bt = new Button(this);
bt.setText("set");
bt.setBackgroundColor(0xff14148c);
위와 같이 했더니 버튼 모양 없이 버튼 영역의 색상이 모두 바뀌었어요;;
버튼 모양을 유지하면서 색상만 바꾸는 메소드는 없나요???
2010.04.01 11:31:58
selector를 이용하면 바꾸실 수 있습니다.
my_button.xml로 drawable폴더에 넣어 주고
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/redbutton" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/bluebutton" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/bluebutton" />
<item android:drawable="@drawable/redbutton" />
</selector>
레이아웃에서 이런식으로 넣으면 됩니다.
<Button
android:id="@+id/big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:text="Biiiiiiig text!"
android:textSize="30sp"
android:background="@drawable/my_button"/>
참고하세요, 각각의 상황에 맞는 이미지를 넣어 주시면 됩니다.
http://chan180.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4-%EC%8A%A4%ED%83%80%EC%9D%BC-%EB%B0%94%EA%BE%B8%EA%B8%B0
참고가 될지도 모르겠네요..