package com.example.yanlei.yl6; import android.annotation.TargetApi; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.view.MotionEvent; import android.view.View; import android.widget.Toast; public void ShowMessage(String str) { Toast.makeText(this, str, Toast.LENGTH_LONG).show(); } public String getApplicationName() { PackageManager packageManager = null; ApplicationInfo applicationInfo = null; try { packageManager = getApplicationContext().getPackageManager(); applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { applicationInfo = null; } String applicationName = (String) packageManager.getApplicationLabel(applicationInfo); return applicationName; } public void ShowMessage1(String str) { new AlertDialog.Builder(this) .setTitle(getApplicationName()) .setMessage(str) .show(); } public void ShowMessage2(String str) { // new AlertDialog.Builder(this) .setMessage(str) .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { //按钮事件 } }) .show(); } public void ShowMessage3(String str) { // new AlertDialog.Builder(this) .setTitle("提示") .setMessage(str) .setIcon(R.drawable.quit) .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setResult(RESULT_OK);//确定按钮事件 finish(); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //取消按钮事件 } }) .show(); }