package com.JIN;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
public class firstActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar=getSupportActionBar();
actionBar.hide();
setContentView(R.layout.activity_first);
TextView t1=findViewById(R.id.add);
TextView t2=findViewById(R.id.look);
t2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(firstActivity.this, MainActivity.class);
startActivity(intent);
}
});
t1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(firstActivity.this, add_Activity.class);
startActivity(intent);
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (((keyCode == KeyEvent.KEYCODE_BACK) ||
(keyCode == KeyEvent.KEYCODE_HOME))
&& event.getRepeatCount() == 0) {
dialog_Exit(firstActivity.this);
}
return false;
}
private void dialog_Exit(Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("确定要退出吗?");
builder.setTitle("提示");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setPositiveButton("确认",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
System.exit(0);
finish();
}
});
builder.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
}