目前我在我的活动中使用dispatchtouchEvent()但如果我在屏幕上有一个对话框,则不会调用它.有没有人知道我是否有任何方法可以在存在对话框的情况下使用相同的功能?
谢谢
解决方法 要在DialogFragment中使用dispatchtouchEvent(),请覆盖onCreateDialog并使用dispatchtouchEvent返回自定义Dialog(在自定义DialogFragment中).例如,在DialogFragment中单击外部时关闭键盘:
@NonNull@OverrIDepublic Dialog onCreateDialog(Bundle savedInstanceState) { return new Dialog(getActivity(),gettheme()) { @OverrIDe public boolean dispatchtouchEvent(@NonNull MotionEvent motionEvent) { if (getCurrentFocus() != null) { inputMethodManager inputMethodManager = (inputMethodManager) getContext().getSystemService(Context.input_METHOD_SERVICE); inputMethodManager.hIDeSoftinputFromWindow(getCurrentFocus().getwindowToken(),0); } return super.dispatchtouchEvent(motionEvent); } };}总结
以上是内存溢出为你收集整理的android – Dialog或DialogFragment中的Activity是否存在dispatchTouchEvent()的等价物全部内容,希望文章能够帮你解决android – Dialog或DialogFragment中的Activity是否存在dispatchTouchEvent()的等价物所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)