1

Ich habe ein Fragment, das über die Aktivität angezeigt werden muss, aber die Schaltfläche in der Aktivität wird weiterhin über das Fragment angezeigt. Ich brauche das Fragment, um die Aktivität vollständig zu überlappen.Schaltfläche auf Aktivität zeigt über Fragment

Das XML der Aktivität.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@color/colorPrimary" 
    android:minHeight="?attr/actionBarSize" 
    app:navigationIcon="@drawable/ic_close_black_24dp" 
    app:popupTheme="@style/Theme.AppCompat.NoActionBar" 
    app:titleTextColor="@color/toolbarTextColor" /> 

<android.support.design.widget.TextInputLayout 

    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:inputType="textMultiLine" 
     android:lines="3" 
     android:maxLines="10" 
     android:scrollbars="vertical" /> 


</android.support.design.widget.TextInputLayout> 

</LinearLayout> 

Das Fragment

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/colorPrimary" 
     android:minHeight="?attr/actionBarSize" 
     app:navigationIcon="@drawable/ic_close_black_24dp" 
     app:popupTheme="@style/Theme.AppCompat.NoActionBar" 
     app:titleTextColor="@color/toolbarTextColor" /> 

    <TextView 
     android:id="@+id/firstnameTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="@dimen/activity_horizontal_margin" 
     /> 

    <TextView 
     android:id="@+id/lastnameTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="@dimen/activity_horizontal_margin" 
     /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:text="Chat" /> 

    <fragment 
     android:id="@+id/fragment_chat" 
     android:name="user.InitiateChat_Fragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</FrameLayout> 

The incorrect Image

private void init() { 
    final FragmentManager fragmentManager = getSupportFragmentManager(); 
    fragment = fragmentManager.findFragmentById(R.id.fragment_chat); 
    final FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); 
    fragmentTransaction.hide(fragment); 
    fragmentTransaction.commit(); 
} 

public void showChatForm() { 
    showHideFragment(fragment); 
} 

private void showHideFragment(final Fragment fragment) { 

    final FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction(); 
    fragTransaction.setCustomAnimations(R.anim.fragment_slide_from_bottom, R.anim.fragment_slide_to_bottom); 

    if (fragment.isHidden()) { 
     fragTransaction.show(fragment); 
    } else { 
     fragTransaction.hide(fragment); 
    } 
    fragTransaction.commit(); 
} 

Der init-Code auf die Aktivität create.Fragment genannt wird, ist eine globale Variable.

+0

senden Screenshot es uns besser –

+0

Diese Schaltfläche wird über dem Fragment angezeigt? –

+0

Ersetzen Sie das Layout für die Aktivität durch framelayout und fügen Sie die Fragmente nach Wunsch mit add() oder replace() hinzu. Die Aktivität sollte nur den Container zum Halten der Fragmente enthalten. –

Antwort

1

Try this:

<fragment 
    android:id="@+id/fragment_chat" 
    android:name="user.InitiateChat_Fragment" 
    android:layout_width="match_parent" 
    android:background="?android:attr/colorBackground" //add this 
    android:layout_height="match_parent" /> 

2. Way

ein Layout in Ihrem Fragmente erstellen und verstecken es Sichtbarkeit ist während zeigt das Fragment

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/colorPrimary" 
     android:minHeight="?attr/actionBarSize" 
     app:navigationIcon="@drawable/ic_close_black_24dp" 
     app:popupTheme="@style/Theme.AppCompat.NoActionBar" 
     app:titleTextColor="@color/toolbarTextColor" /> 

    <LinearLayout 
     android:id="@+id/activity_button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/firstnameTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="@dimen/activity_horizontal_margin" /> 

     <TextView 
      android:id="@+id/lastnameTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="@dimen/activity_horizontal_margin" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

      android:text="Chat" /> 

    </LinearLayout> 

    <fragment 
     android:id="@+id/fragment_chat" 
     android:name="user.InitiateChat_Fragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</FrameLayout> 

Jetzt in Ihrem Code: layout_width = "wrap_content" android: layout_height = "wrap_content"

private void showHideFragment(final Fragment fragment) { 

    final FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction(); 
    fragTransaction.setCustomAnimations(R.anim.fragment_slide_from_bottom, R.anim.fragment_slide_to_bottom); 

    if (fragment.isHidden()) { 
     fragTransaction.show(fragment); //show fragment 
     layout.setVisibility(View.GONE); //hide Linearlayout 
    } else { 
     fragTransaction.hide(fragment); 
    } 
    fragTransaction.commit(); 
} 

Wo LinearLayout layout =(LinearLayout)findViewById(R.id.activity_button);

+0

Irgendwie schien das zu funktionieren, ich habe nur den XML-Teil hinzugefügt und das war gut zu gehen. –

0

Versuchen Hinzufügen von Hintergrundfarbe zu Ihrem Fragmente wie diese

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" /* Add any color you want */ 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools"> 
+0

das hat nicht funktioniert, der Knopf erscheint immer noch über dem Fragment –

Verwandte Themen