Android FloatingActionButton在片段更改后未消失

Android FloatingActionButton在片段更改后未消失,android,Android,我正在制作一个基本的android应用程序。我在第一个片段中使用了一个按钮来导航到第二个片段。 最初,第一个片段没有消失,而是与新片段重叠。然后我在片段中添加了背景,但按钮仍然没有消失。按钮仍然保留在上一个片段中。 如何移除此按钮以便可以使用新片段的按钮 HomeFragment.java public class HomeFragment extends Fragment implements OnClickListener{ FloatingActionButton fab; public

我正在制作一个基本的android应用程序。我在第一个片段中使用了一个按钮来导航到第二个片段。 最初,第一个片段没有消失,而是与新片段重叠。然后我在片段中添加了背景,但按钮仍然没有消失。按钮仍然保留在上一个片段中。 如何移除此按钮以便可以使用新片段的按钮

HomeFragment.java

public class HomeFragment extends Fragment implements OnClickListener{
FloatingActionButton fab;

public HomeFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home, container, false);
        ((FloatingActionButton) rootView.findViewById(R.id.fab)).setOnClickListener(this);
        return rootView;
    }

    public void onClick(View view) {
        TeamFragment fragment2 = new TeamFragment();
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction Transaction = fragmentManager.beginTransaction();
        Transaction.replace(R.id.fragmenthome, fragment2);
        Transaction.addToBackStack(null);
        Transaction.commit();
    }
public class TeamFragment extends Fragment {

public TeamFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_teamname, container, false);
    // Inflate the layout for this fragment
    return rootView;
}
TeamFragment.java

public class HomeFragment extends Fragment implements OnClickListener{
FloatingActionButton fab;

public HomeFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home, container, false);
        ((FloatingActionButton) rootView.findViewById(R.id.fab)).setOnClickListener(this);
        return rootView;
    }

    public void onClick(View view) {
        TeamFragment fragment2 = new TeamFragment();
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction Transaction = fragmentManager.beginTransaction();
        Transaction.replace(R.id.fragmenthome, fragment2);
        Transaction.addToBackStack(null);
        Transaction.commit();
    }
public class TeamFragment extends Fragment {

public TeamFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_teamname, container, false);
    // Inflate the layout for this fragment
    return rootView;
}
Fragment_home.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/fragmenthome"
tools:context="app.tuhinsidd.cop290registration.activity.HomeFragment"
android:background="@android:color/white"
android:clickable="true">


<TextView
    android:id="@+id/label"
    android:layout_alignParentTop="true"
    android:layout_marginTop="80dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:textSize="45dp"
    android:text="WELCOME"
    android:textStyle="bold"/>

<TextView
    android:layout_below="@id/label"
    android:layout_centerInParent="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="12dp"
    android:layout_marginTop="20dp"
    android:gravity="center_horizontal"
    android:text="This is an app to register yourselves on the course COP290" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="40dp"
    android:elevation="3dp"
    android:tint="#ffffff"
    android:src="@android:drawable/ic_input_add"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />
<TextView
    android:layout_alignParentBottom="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="12dp"

    android:layout_marginBottom="10dp"
    android:gravity="center_horizontal"
    android:text="Created by Tuhinanksu Das and Siddharth Jain" />

</RelativeLayout>

fragment_teamname.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/teamfragment"
tools:context="app.tuhinsidd.cop290registration.activity.FriendsFragment"
android:background="@android:color/white"
android:clickable="true">


<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="350dp"
    android:layout_marginTop="?attr/actionBarSize"
    android:orientation="vertical"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingTop="20dp">
<TextView
    android:id="@+id/label"
    android:layout_alignParentTop="true"
    android:layout_marginTop="10sp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:textSize="45dp"
    android:text="TEAM NAME"
    android:textStyle="bold"/>

<TextView
    android:layout_below="@id/label"
    android:layout_centerInParent="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="12dp"
    android:layout_marginTop="20dp"
    android:gravity="center_horizontal"
    android:text="Please enter the name of your team below"
    android:id="@+id/textView" />


<android.support.design.widget.TextInputLayout
    android:id="@+id/input_layout_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/input_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:hint="@string/hint_name" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>




<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="40dp"
    android:elevation="3dp"
    android:tint="#ffffff"
    android:src="@drawable/ic_arrow"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />



</RelativeLayout>


如果还需要什么,请告诉我。

给出您的
FloatingActionButton

app:elevation=“0dp”

原因:

你的意思是我应该将android:elevation=“3dp”更改为0dp?这很有效。谢谢但是你能告诉我提升的目的是什么吗?非常有用;)