以下代码适用于 ICS 而不是 2.3.3。
我使用带有 CheckBox 的自定义 Toast 并在 ICS 上触发 clickEvents。
我是否必须创建一个自定义对话框并将其称为活动,或者我可以解决它?
public void showToastwithImage(String text, int imageID, boolean forceShow) {
if (prefs.getBoolean("prefs_showHelp", true)) {
// create the view
View view = inflateView(R.layout.message_panel);
// set the image in the view
ImageView im = (ImageView) view.findViewById(R.id.panel_icon);
im.setImageResource(imageID);
// set the text in the view
TextView tv = (TextView) view.findViewById(R.id.message);
tv.setText(text);
CheckBox cb = (CheckBox) view.findViewById(R.id.checkBox1);
if(forceShow){
cb.setVisibility(View.GONE);
}else{
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("prefs_showHelp", false);
editor.commit();
}
});
}
// show the toast
Toast toast = new Toast(this);
toast.setView(view);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
}
}
private View inflateView(int resource) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return vi.inflate(resource, null);
}