Reputation: 101
As the title says I am not able to remove the action bar present in the bottom navigation bar. I tried different NoAction bar themes but it won't work for some reason.
Can someone tell me what am I doing wrong?
Here is the example The screenshot
Upvotes: 6
Views: 8783
Reputation: 1
For Kotlin users:
// Add this to your class Mainactivity
supportActionBar?.hide()
Code looks like this in my MainActivity:
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val navView: BottomNavigationView = binding.navView
val navController = findNavController(R.id.nav_host_fragment_activity_main)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
)
)
setupActionBarWithNavController(navController, appBarConfiguration)
supportActionBar?.hide()
navView.setupWithNavController(navController)
}
}
Upvotes: 0
Reputation: 21
So I might be late to this post... but I believe I found the solution for anyone still wondering. Once you change your theme to a .NoActionBar you will want to comment out these lines of code in the onCreate function of your MainActivity.kt.
This still allows the bottom navigation bar to work.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navView: BottomNavigationView = findViewById(R.id.nav_view)
navController = findNavController(R.id.nav_host_fragment)
floatingActionButton = findViewById(R.id.fab_add)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
// val appBarConfiguration = AppBarConfiguration(setOf(
// R.id.navigation_home, R.id.navigation_leagues, R.id.navigation_practice, R.id.navigation_profile))
//setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}
Upvotes: 1
Reputation: 5604
ActionBar is good for User Interface, but sometimes we do want to hide it. Here we will see the ways to do it.
1. Through code:
You can hide it in your onCreate
method:
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.my_activity)
supportActionBar?.hide()
}
}
This line supportActionBar?.hide()
did the job. Start the app, and it works.
2. Though the XML with theme
First, add a new style in the styles.xml
:
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then, open the AndroidManifest.xml
and apply it to the activity you want to hide the action bar. Start the app, and it works.
<activity
android:name=".ui.MyActivity"
android:theme="@style/AppTheme.NoActionBar"
/>
Upvotes: 1
Reputation: 241
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notification).build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
Upvotes: 21
Reputation: 11
this is work with me :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// add this line
getSupportActionBar().hide();
...
}
Upvotes: 1
Reputation: 618
try the below code. Just copy the code and add in your styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Upvotes: 1