简体   繁体   English

当由片段替换时,活动按钮仍处于活动状态

[英]Activity Buttons still ACTIVE when replaced by Fragment

Basically, I want to open a fragment from Activity . 基本上,我想从Activity打开一个fragment Everything worked fine (activity button opens the fragment and the fragment shows), until I miss-clicked outside the fragment's layout where one of the Activity button is located and it did its onClick method. 一切正常(活动按钮打开了片段并显示了片段),直到我在Activity按钮之一所在的fragment's布局之外单击Activity右键,并且它执行了onClick方法。 That's why I wondered why is my Activity still active. 这就是为什么我想知道为什么我的Activity仍然活跃的原因。

this is how I open the fragment from Activity 这是我从Activity打开fragment

I tried using .add instead of .replace still the same. 我尝试使用.add代替.replace仍然相同。

@OnClick(R.id.login_register_lbl)
public void registerAction(View view) {
    // TODO register transition...

    FragmentManager fragmentManager = (LoginActivity.this.getFragmentManager());
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    RegisterFragment fragment = new RegisterFragment();
    fragmentTransaction.replace(R.id.fragment_register_holder, fragment);
    fragmentTransaction.commit();
}

在根元素集“ background”,“ clickable = true”&Focusable =“ true”中的片段布局中。

In my opinion you can achieve this functionality by 2 ways: 我认为您可以通过以下两种方法来实现此功能:

  1. Open a dialog fragment in full screen mode to avoid accidentally clicks on activities views. 以全屏模式打开对话框片段,以避免意外单击活动视图。

  2. If you wanted to show both fragment's and activity's views at the same time then, on click of your activity's button which opens the fragment, disable it by yourbutton.setenabled(false); 如果您想同时显示片段和活动的视图,则单击活动片段的按钮以打开片段,然后通过yourbutton.setenabled(false);将其禁用yourbutton.setenabled(false); and when you wanted to close the fragment enable that button again. 当您要关闭片段时,请再次启用该按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM