本文介绍了Android的显示后退按钮取决于backstack数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示或隐藏取决于当前backstack条目计数操作栏的后退按钮。这意味着我要表现出来时,有一个片段(或以上)的backstack,并隐藏在backstack是空的​​。

  getSupportActionBar()setDisplayHomeAsUpEnabled(B)。
 

现在的问题是,当我开始一个新的片段,并要求当前backstack条目计数,它还是一样像以前一样。几毫秒后,它刷新。

另外,在开始片段的onResume方法,所述置换片段仍然不能在backstack发现,backstack计数仍然是相同的。

目前我有,经过50毫秒刷新按钮的AsyncTask的。工作,但这不能得到很好的解决。

任何想法?

最好的问候


编辑:
溶液

  fragmentManager.addOnBackStackChangedListener(...)
 

解决方案

有没有必要的AsyncTask 您已经有一个 Backstack 接口时,一个片段将被加入您的通话或删除 onBackStackChangeListener 这样反而实现这一点,叫 getBackstackEntryCount()如果不为0,那么你就知道你会做什么

您需要将您的交易添加到 Backstack 后,你的添加()替换()上调用你的 FragmentTransaction 这样的 .addToBackstack(以下简称标识)

some间接的帖子

希望它可以帮助

I want to show or hide the back button of the action bar depending on the current backstack entry count. That means I want to show it when there is a fragment (or more) in the backstack, and hide when backstack is empty

getSupportActionBar().setDisplayHomeAsUpEnabled(b);

The problem is, when I start a new fragment and ask for the current backstack entry count, it's still the same like before. It refreshes after some milliseconds.

Also in the started fragment's onResume method, the replaced fragment still can not be found in backstack, backstack count is still the same.

Currently I have an AsyncTask that refreshes the button after 50 milliseconds. Working, but this can't be a good solution.

Any ideas?

Best regards


Edit:
Solution was

fragmentManager.addOnBackStackChangedListener(...)
解决方案

There is no need for AsyncTask you already have a Backstack interface that triggers when a Fragment is being added or removed onBackStackChangeListener so instead of your call implement that and call getBackstackEntryCount() if its not 0 then you know what you will do

you need to add your transaction to the Backstack after your add() or replace() calls on your FragmentTransaction like this .addToBackstack("the identifier")

some indirect post

Hope it helps

这篇关于Android的显示后退按钮取决于backstack数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 01:42