【问题标题】:Fab button on tabview when clicked not replacing another Fragment单击时选项卡视图上的 Fab 按钮不替换另一个片段
【发布时间】:2017-11-28 09:14:01
【问题描述】:

我有Fragment 本身的标签视图。在第一个选项卡上,我有 FAB 按钮。当FAB button 被单击时,它不会用新的Fragment 布局替换选项卡视图布局。新的Fragment 布局在选项卡视图布局上重叠。

【问题讨论】:

  • 你能显示一些代码吗?
  • 问题在于您在其上提交片段事务的容器。

标签: android fragment


【解决方案1】:

这里使用替换而不是添加是示例

FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
transaction.replace(R.id.totalpropcontainer, contactUs);//Replace by your fragment
transaction.commit();

【讨论】:

    【解决方案2】:

    首先,您必须初始化 fab 按钮静态,如果您有五个选项卡并在第一个选项卡中打开,请单击 set fab.setVisibility(View.VISIBLE);和其他标签点击 fab.setVisibility(View.GONE);

    或者在工厂,按钮点击你写这段代码:

       FragmentTransaction ft =  getSupportFragmentManager().beginTransaction();
                ft.replace(R.id.content_frame, new yourFragment());
                ft.commit();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-15
      • 2013-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多