软件后退按钮 android
Software back button android
我需要一个后退按钮,其功能与设备的默认后退按钮相同,但在应用程序内部。
Android 活动存储在 activity 堆栈中。您只需完成当前 activity:
即可返回
向 activity xml 中的按钮添加一个 onClick
侦听器,如下所示:
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/self_destruct"
android:onClick="selfDestruct" />
然后在您的 activity 中创建一个与您在 xml
中指定的名称相同的方法
public void selfDestruct(View view) {
finish()
}
您可以在 docs.
中阅读更多内容
我需要一个后退按钮,其功能与设备的默认后退按钮相同,但在应用程序内部。
Android 活动存储在 activity 堆栈中。您只需完成当前 activity:
即可返回向 activity xml 中的按钮添加一个 onClick
侦听器,如下所示:
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/self_destruct"
android:onClick="selfDestruct" />
然后在您的 activity 中创建一个与您在 xml
中指定的名称相同的方法 public void selfDestruct(View view) {
finish()
}
您可以在 docs.
中阅读更多内容