Tag: android button

如何开始按钮点击新的活动

在Android应用程序中,如何在单击另一个活动中的按钮时启动新的活动(GUI),以及如何在这两个活动之间传递数据?

Android单击时更改背景颜色

我试图改变一个Button的背景颜色,点击时,我可以改变背景颜色,当我按下Button时,我释放Button按钮返回到它的默认颜色。 我不知道从哪里去,我一直在试图找到解决这个问题的方法。 ` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.game.dice.MainActivity"> <Button android:id="@+id/but1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 1" android:background="@drawable/button_color" /> <Button android:id="@+id/but2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" android:background="@drawable/button_color"/> </LinearLayout> ` <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@color/button_pressed"/> <item android:state_focused="true" android:drawable="@color/button_focused"/> <item android:drawable="@color/button_default"/> </selector>