ProgressDialog,SharedPreferences,Toast自定义,versionName ,new AlertDialog.Builder和下载更新

一.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();

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值