In my app I have an activity showing a CoordinatorLayout having ViewPager2 showing 3 tabs, each having a RecyclerView. When scrolling up, the top MaterialToolBar goes under the (opaque) status bar, and my tab titles stops moving when their top touches the status bar bottom.
Updated the app to target Android 16, and now the AppBarLayout is displayed above the status bar.
Here's a sample code:
Activity:
class MyAdapter(private val items: List) : RecyclerView.Adapter() {
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val textView: TextView = view.findViewById(android.R.id.text1)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
// Using a simple built-in Android layout for the demo
val view = LayoutInflater.from(parent.context)
.inflate(android.R.layout.simple_list_item_1, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.textView.text = items[position]
// Setting a minimum height to ensure the list is long enough to scroll
holder.itemView.minimumHeight = 200
}
override fun getItemCount() = items.size
}
class TabListFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val recyclerView = inflater.inflate(R.layout.activity_test_fragment, container, false) as RecyclerView
// Setup Dummy Data
recyclerView.layoutManager = LinearLayoutManager(context)
recyclerView.adapter = MyAdapter((1..50).map { "Item $it" })
// 5. Handle Bottom Insets for the List
// Ensures the last item in the list is fully visible above the nav bar
ViewCompat.setOnApplyWindowInsetsListener(recyclerView) { v, insets ->
val navBars = insets.getInsets(WindowInsetsCompat.Type.navigationBars())
v.updatePadding(bottom = navBars.bottom + 100) // 100px extra for FAB clearance
insets
}
return recyclerView
}
}
class TestActivity : AppCompatActivity() {
private lateinit var ui: ActivityTestBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
ui = ActivityTestBinding.inflate(layoutInflater)
setContentView(ui.root)
// Set action bar:
setSupportActionBar(ui.toolBar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
// Setup ViewPager and Tabs
ui.viewPager.adapter = object : FragmentStateAdapter(this) {
override fun getItemCount(): Int = 3
override fun createFragment(position: Int) = TabListFragment()
}
TabLayoutMediator(ui.tabLayout, ui.viewPager) { tab, position ->
tab.text = "TAB ${position + 1}"
}.attach()
}
}
Activity XML:
Tab XML:
And here's the result when scrolled:

How to make the AppBarLayout go under the status bar as before?