我喜欢这在我的java文件
final Button btn_showtouch = (Button)findViewById(R.id.button);
btn_showtouch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((btn_showtouch.getText()).equals("YES")) {
btn_showtouch.setBackgroundColor(Color.GREEN);
btn_showtouch.setText("NO");
}else if(btn_showtouch.getText().equals("NO")) {
btn_showtouch.setBackgroundColor(Color.CYAN);
btn_showtouch.setText("YES");
}
}
});
}
像这样
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YES"
android:id="@+id/button"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="62dp" />
和XML文件的工作对我来说,我希望这会帮助你