我已經在它的下方的一些按鈕一個Android活動,這些按鈕都一個一個按下並釋放爲默認三,按鈕按下
,並在任何時候奇怪的行爲他們按下它的背景應該改變到按下按鈕的背景和其他背景應該改變,以釋放按鈕的背景,但點擊任何按鈕時,我得到的結果是:
這是我的代碼:
的xml:
<LinearLayout
android:id="@+id/GrandThree"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:background="@android:color/transparent">
<Button
android:id="@+id/BedRoom_bottom"
android:layout_width="200dp"
android:layout_height="fill_parent"
android:background="@drawable/light_bottom_buttons_pressed"
android:text="Bedroom"
android:textSize="20dp"
android:textColor="#FFFFFF"
android:layout_gravity="center"
android:layout_marginTop="3dp"
android:layout_marginLeft="3dp"
android:layout_marginBottom="3dp"
android:layout_marginRight="3dp"
android:tag="pressed"
android:clickable="true" />
<Button
android:id="@+id/livingroom"
android:layout_width="200dp"
android:layout_height="fill_parent"
android:background="@drawable/light_bottombuttons"
android:text="Living Room"
android:layout_gravity="center"
android:textSize="20dp"
android:padding="20px"
android:textColor="#FFFFFF"
android:layout_marginTop="3dp"
android:layout_marginLeft="3dp"
android:layout_marginBottom="3dp"
android:layout_marginRight="3dp"
android:tag="released"
android:clickable="true" />
<!.. then two buttons the same way ..!>
</LinearLayout>
JAVA:
// the onClickListener method for the Navigation buttons
public OnClickListener onNavigationClick = new OnClickListener() {
@Override
public void onClick(View v) {
if(v == bedRoom){
String tag = bedRoom.getTag().toString().trim();
if (tag.equals("released")) {
bedRoom.setBackgroundColor(R.drawable.light_bottom_buttons_pressed);
bedRoom.setTag("pressed");
livingRoom.setBackgroundColor(R.drawable.light_bottombuttons);
livingRoom.setTag("released");
masterBedroom.setBackgroundColor(R.drawable.light_bottombuttons);
masterBedroom.setTag("released");
kitchen.setBackgroundColor(R.drawable.light_bottombuttons);
kitchen.setTag("released");
}
}
//then another 3 blocks the same way for the other buttons
}
};
提示: light_bottombuttons & light_bottom_buttons_pressed是形狀,其具有漸變的顏色:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="30dp"/>
<gradient
android:startColor="#353535"
android:centerColor="#212121"
android:endColor="#121212" <!.. the values of the other is just upside down these values ..!>
android:angle="270"/>
</shape>