Java VIewRootImpl由于没有窗口焦点、浮动按钮而取消事件
我已经在寻找一个类似的答案,但没有一个对我有效。我只是在Android Studio中学习编码,在学习过程中,我遇到了以下警告:Java VIewRootImpl由于没有窗口焦点、浮动按钮而取消事件,java,android,android-studio,Java,Android,Android Studio,我已经在寻找一个类似的答案,但没有一个对我有效。我只是在Android Studio中学习编码,在学习过程中,我遇到了以下警告: W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, 我有一个带有floatingAction按钮的简单活动(滚动活动)。 以下是活动的代码: public class ImmobileActivity extends AppCompa
W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL,
我有一个带有floatingAction按钮的简单活动(滚动活动)。
以下是活动的代码:
public class ImmobileActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String msg = getIntent().getStringExtra(FrontActivity.MESSAGE);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener((View v) -> {
Intent send = new Intent();
send.setAction(Intent.ACTION_SENDTO);
send.putExtra(Intent.EXTRA_TEXT,msg);
send.setType("text/plain");
String title = getResources().getString(R.string.app_name);
Intent chooser = Intent.createChooser(send,title);
if(send.resolveActivity(getPackageManager())!= null) {
startActivity(chooser);
}
});
}
所以。。。我不知道如何实现onTouchEvent(),正如本文所建议的那样
有什么建议吗 你有没有显示对话?当显示系统警报类型的对话框,但将活动上下文而不是应用程序上下文提供给它时,通常会发生这种情况。请发布更多代码。@JasonChueh您的答案是正确的。