android 加一个按钮,退出程序
package com.example.yanlei.yl; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; import android.text.Html; import android.text.Html.ImageGetter; import java.util.regex.Matcher; import java.util.regex.Pattern; import android.text.Editable; import android.text.TextWatcher; import android.widget.EditText; import android.widget.Button; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View btn1 = this.findViewById(R.id.button1); btn1.setOnClickListener(new ButtonClickListener()); } private class ButtonClickListener implements View.OnClickListener { public void onClick(View v) { //System.exit(0); android.os.Process.killProcess(android.os.Process.myPid()); } }
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="退出程序" android:id="@+id/button1" android:layout_marginTop="157dp" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="96dp" android:layout_marginStart="96dp" />