Fragment's Transaction replace on API-21 is staying behind

不想你离开。 提交于 2019-12-01 18:08:37

The possible issue may be the code:

if (mFragmentFeedBack.isVisible())

I don't recommend using this method for checking visibility. According to documentation @ Fragment isVisible(), it says

...This means it: (1) has been added, (2) has its view attached to the window, and (3) is not hidden.

This part of the sentence is not very clear. I suspect KitKat says it is NOT visible but Lollipop says it is, and I agree with Lollipop implementation. KitKat says the Fragment is added (yes), the view is attached (yes), hidden (not really!). This is actually a GUI issue with other GUI libraries, believe it or not!

Possible solutions, for now:

  1. Create a boolean flag, and maintain the flag between the 2 fragments. If this is simple to do, this is best.
  2. Check if a button or view is clickable, don't know which one. This is more solid than checking for isVisible().
  3. I think the code design is a bit more complicated than it should be. For now, this is my suggestion. When user hits "New Button", just call the replace() method, don't use the hide/show methods. When user hits the SEND button in the feedback fragment, either call popBackStack() or replace() methods. How about that?
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!