To make a more complete answer to the BENN1TH question, I did throw a snippet from the tabbed ActivityMain.
public class MainActivity extends AppCompatActivity { Button throwFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); throwFragment = (Button) findViewById(R.id.throwFragment);
activity_main.xml A layout that belongs to the main activity, where I created a button to cut out a fragment at runtime.
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true" tools:context="org.itdevelopers.braian.tabsinsidefragment.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:id="@+id/containerTabs"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center"> <Button android:id="@+id/throwFragment" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:text="I throw fragment with tabs" /> </LinearLayout> </android.support.design.widget.CoordinatorLayout>
IMPORTANT The main activity will be the context of the fragment with tabs, in which case it is necessary to note the importance of the next line in order to follow the style in the design.
It has the functionality that the main action toolbar does not overlap with the TabLayout fragment.
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Running a snippet with tabs can be very useful when using the bottom navigation bar, because if we use the default tabs that are involved in activity, it will require more resources (check this in Android-Logcat using "No Filters", in milliseconds).
- The moral of the story *: It is preferable to use a TabbedFragment.
This is my first comment in the community, I hope I can work with something. Thanks.
source share