Issue
In order to be able to see the content of a certain view inside a fragment when previewing a layout in Android Studio, it is possible to do this:
<MainLayoutView 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">
<fragment
...
tools:layout="@layout/my_fragment_view"/>
</MainLayoutView>
However, if you switch from fragment
to androidx.fragment.app.FragmentContainerView
, this handy tool stops working and the fragment just appears blank on the preview screen.
Is there any way to show content inside a FragmentContainerView
when previewing it in a layout in Android Studio?
Solution
As stated in the comment by tir38 this was fixed in later versions of Android Studio, you can now use the tools:layout attribute in the FragmentContainerView. In cases where you are using Navigation component, if you define a startDestination for your Navigation graph which uses the tools:layout attribute, this will automatically be reflected in your FragmentContainerView
<androidx.fragment.app.FragmentContainerView
...
app:navGraph="@navigation/nav_graph"/>
<navigation
...
app:startDestination="@id/someFragment">
<fragment
...
android:id="@+id/someFragment"
tools:layout="@layout/fragment_splash"/>
</navigation>
Answered By - Mats
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.