工作日记第三篇(DialogFragment)

一个简单的版本更新提示,用的是DialogFragment(本人建议写弹框的时候使用DialogFragment)

/** * Created by Mr.Xu on 2016/4/11. */
public class UpdateDialog extends DialogFragment {    

private List features;   
 private Context mContext;    

public UpdateDialog(FlashBean flash, Context context) {        
this.features = flash.getData().getNewFeatures();        
this.mContext = context;    
}    

LinearLayout parentView;    
UniteThemeButton dialog_update_send;   

public interface onUpdateClickListener {        
void onUpdate();   
}    
private onUpdateClickListener updateListener;    

public void setUpdateListener(onUpdateClickListener updateListener) {        
this.updateListener = updateListener;   
 }    

@Override    
public void onStart() {        
super.onStart();        
//去掉Dialog默认的黑色背景
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));   
 }    

@Override    
public void onCreate(Bundle savedInstanceState) {          
super.onCreate(savedInstanceState);        
setCancelable(false);  
  }   

 @Nullable    
@Override    
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {        
 //去掉标题栏
 getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);       
 View view = inflater.inflate(R.layout.dialog_update_confirm, null);       

 parentView = (LinearLayout) view.findViewById(R.id.dialog_update_content);      
 dialog_update_send = (UniteThemeButton) view.findViewById(R.id.dialog_update_send); 

 dialog_update_send.setOnClickListener(new View.OnClickListener() {    
        @Override           
         public void onClick(View v) {               
       if (updateListener != null)                 
        updateListener.onUpdate();           
 }       
 });   

for (FlashBean.DataBean.NewFeaturesBean feature : features ) {     
 TextView featureTxt = new TextView(mContext);    

 featureTxt.setText(feature.getNewFeature());   

 featureTxt.setTextColor(getResources().getColor(R.color.black)); 

 featureTxt.setTextSize(18);           

 LinearLayout.LayoutParams params = new  LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,  ViewGroup.LayoutParams.WRAP_CONTENT);           

 params.setMargins(10, 10, 10, 10);          
 
 featureTxt.setLayoutParams(params);    
       
 parentView.addView(featureTxt);        
 }       
 return view;    
}

}

你可能感兴趣的:(工作日记第三篇(DialogFragment))