一.ProgressDialog的使用:
pd = ProgressDialog.show(view.getContext(), "登陆",
"登陆中,请稍候...", true, false);
使用完要关闭:pd.dismiss();
二.SharedPreferences的使用:
sharedPreferences2 = getSharedPreferences("ddname", Context.MODE_PRIVATE);
editor2 = sharedPreferences2.edit();
editor2.clear();
editor2.putString("dd_Name",usernametext);
editor2.commit();//别忘了提交哦
//获取sharedPreferences中值
public static String getUserName(Activity context) {
SharedPreferences sharedPreferences=context.getSharedPreferences("ddname",Context.MODE_PRIVATE);
String username= sharedPreferences.getString("dd_Name", "");
return username;
}
三.Toast自定义:
WindowManager wm = (WindowManager) mActivity
.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
TextView textView=new TextView(mActivity);
textView.setText("+"+(refresh_childCount-childCount));
textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.toast_bg));
textView.setGravity(Gravity.CENTER);
textView.setWidth(width/6);
textView.setHeight(width/6);
textView.setTextColor(Color.parseColor("#009cff"));
Toast toastStart = new Toast(mActivity);
toastStart.setGravity(Gravity.TOP, width/16,height/15);
toastStart.setDuration(Toast.LENGTH_LONG);
toastStart.setView(textView);
toastStart.show();
四.versionName的获取:
versionName = this.getPackageManager().getPackageInfo(
this.getPackageName(), 0).versionName;
五.new AlertDialog.Builder和下载更新:
new AlertDialog.Builder(this)
.setTitle("软件升级").setMessage(Html.fromHtml("有软件升级,是否更新?<br>(建议在wifi环境下更新)<br>"+fileExplain+"<br>文件大小为:"+fileSize+"m"))
.setNegativeButton("是", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("http://"+ServerAndPort.ServerIP+":"+ServerAndPort.AppPort+"/floodwarn/apk/"+fileName+".apk");
intent.setData(content_url);
startActivity(intent);
finish();
}
}).setPositiveButton("否", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).show();