to declare that a activity is a child of another activity and show the back button in the appbar so that we the user clicks it it goes back to the parent activity we add the following code to the manifest:
android:parentActivityName=".MainActivity">- In order to use a Toolbar rather than an app bar and app title, add the following attributes to the res > values > styles.xml file to hide the app bar and the title:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Other style attributes -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>with that code the default appbar is removed.
we can add a toolbar to activity xml and then we should infiltrate it as the app bar.Visit Mainactivity to see how it is done.
//To add the toolbar to the activity as the appbar.
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);there are two usage for this:
- Lateral navigation from one category screen to another
- Lateral navigation from one story screen to another
- The primary class used for tabs is TabLayout in the Android Design Support Library.
- ViewPager is a layout manager that allows the user to flip left and right through pages of data. ViewPager is most often used in conjunction with Fragment.
- Use one of the two standard adapters for using ViewPager: FragmentPagerAdapter or FragmentStatePagerAdapter.
- FragmentPagerAdapter: Designed for navigating between sibling screens (pages) representing a fixed, small number of screens.
- FragmentStatePagerAdapter: Designed for paging across a collection of screens (pages) for which the number of screens is undetermined. It destroys each Fragment as the user navigates to other screens, minimizing memory usage.
The adapter-layout manager pattern lets you provide different screens of content within an Activity:
- Use an adapter to fill the content screen to show in the Activity.
- Use a layout manager that changes the content screens depending on which tab is selected.
- We added a TabLayout and a PagerView to the xml of the activity.
- We Added the PagerAdapter Class that extends FragmentStatePagerAdapter
- We inflate the TabLayout in the mainactivity.
- Use PagerAdapter to manage screen views
- set a listener (TabLayoutOnPageChangeListener) to detect if a tab is clicked, and create the onTabSelected() method to set the ViewPager to the appropriate tabbed screen.