Home > Blockchain >  How to hide the default fragment actionBar create our own actionBar in android & kotlin
How to hide the default fragment actionBar create our own actionBar in android & kotlin

Time:09-17

I have an android app with bottom navigation containing 3 fragments and all have their own actionBar by default. I want to hide all the default actionBar of three fragments and create my own actionbar with many options. I am using Kotlin.

CodePudding user response:

You just need to set the style of the app. Go to values/styles.xml, edit the value of AppTheme as NoActionBar. Then to create your own AppBar in each fragments, just use AppBarLayout in your Xml. For instance:

 <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
       ...
 </style>

CodePudding user response:

Heres a quick solution.

You find styles.xml and you change the base application theme to "Theme.AppCompat.NoActionBar" as shown below.

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
</style>

and define custom layout of action bar in xml

CodePudding user response:

I have solved the problem.

val appBarConfiguration = AppBarConfiguration(setOf( R.id.navigation_home, R.id.navigation_messages, R.id.navigation_profile)) 
setupActionBarWithNavController(navController, appBarConfiguration)

Just remove the above two lines from the main activity and your problem is solved.

CodePudding user response:

First of all, ActionBar is Activities property, not fragments. If you want a custom action bar follow this link, https://myandroid.site/custom-toolbar-with-style-in-kotlin-design-colorful-toolbar/

or

You can have the default ActionBar in Activity & create your own layout that look like an action bar.

Hide Action Bar(Below code should be inside Activity):

if (supportActionBar != null)
    supportActionBar?.hide() 
  • Related