Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

navigation和fragment一起出现的bug #16

Closed
android-1995 opened this issue Dec 10, 2020 · 3 comments
Closed

navigation和fragment一起出现的bug #16

android-1995 opened this issue Dec 10, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@android-1995
Copy link

android-1995 commented Dec 10, 2020

image

implementation 'com.zackratos.ultimatebarx:ultimatebarx:0.3.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.1'
//activity的布局
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/bug_navigation" />

</FrameLayout>
//navigation的布局
<navigation 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:id="@+id/mobile_navigation"
    app:startDestination="@+id/bugFragment">

    <fragment
        android:id="@+id/bugFragment"
        android:name="com.zackratos.ultimatebarx.sample.BugFragment"
        tools:layout="@layout/fragment_image"/>


</navigation>
//Fragment代码
public class BugFragment extends Fragment {

    public BugFragment() {
        super(R.layout.fragment_image);
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        UltimateBarX.with(this)
                .fitWindow(true)// 布局是否侵入状态栏(true 不侵入,false 侵入)
                .color(Color.BLACK)
                .applyStatusBar();
    }
}

fragment的根布局非FrameLayout和RelativeLayout

//fragment的布局
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ivYurisa"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"/>
@android-1995
Copy link
Author

#3

@android-1995
Copy link
Author

报错的位置

//androidx.fragment.app.FragmentContainerView
@Override
    public void addView(@NonNull View child, int index, @Nullable ViewGroup.LayoutParams params) {
        if (FragmentManager.getViewFragment(child) == null) {
            throw new IllegalStateException("Views added to a FragmentContainerView must be"
                    + " associated with a Fragment. View " + child + " is not associated with a"
                    + " Fragment.");
        }
        super.addView(child, index, params);
    }

@Zackratos
Copy link
Owner

专业的 issues ,下个版本修复这个问题

Zackratos added a commit that referenced this issue Dec 10, 2020
@Zackratos Zackratos added the bug Something isn't working label Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants