【发布时间】:2015-06-28 22:41:51
【问题描述】:
我正在尝试在活动返回结果时显示敬酒消息。但是,我使用的是自定义充气吐司。普通吐司工作正常,但我的自定义吐司不会显示。代码如下。
主要活动的onCreate():
@Override
public void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
setContentView(R.layout.activity_login);
emailTxt = (TextView)this.findViewById(R.id.email_field);
passwordTxt = (TextView)this.findViewById(R.id.password_field);
wgmService = ((MainApp)this.getApplication()).wegmannAdapter.create(WegmannService.class);
spinner = (ProgressBar)this.findViewById(R.id.progress_bar);
spinner.setVisibility(View.GONE);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast, (ViewGroup)findViewById(R.id.toast_layout));
toastText = (TextView)layout.findViewById(R.id.toast_text);
toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
fadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
fadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out);
}
主要活动的onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
switch(requestCode) {
case SIGNUP_VIEW:
if(resultCode == RESULT_OK){
toastText.setText(data.getExtras().getString("message"));
toast.show();
}
break;
}
}
通过以上内容,我看不到 toast 消息。但是,如果我将 onActivityResult 中的行替换为 Toast.makeText(getBaseContext(),"MESSAGE", Toast.LENGTH_LONG).show(),则会出现一条消息。在这种情况下,我需要能够使用我的自定义吐司。任何帮助或指导表示赞赏。
【问题讨论】:
标签: java android toast onactivityresult