我有一個安卓應用,它的底部導航包含3個片段,所有這些片段默認都有自己的動作條。我想隱藏三個片段的所有默認動作條,并創建我自己的具有許多選項的動作條。我使用的是Kotlin.
。uj5u.com熱心網友回復:
你只需要設定應用程式的樣式。進入values/styles.xml,編輯AppTheme的值為NoActionBar。然后在每個片段中創建你自己的AppBar,只要在你的Xml中使用AppBarLayout。例如:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar" >
...
</style>
uj5u.com熱心網友回復:
這是一個快速的解決方案。
你找到style.xml,并將基礎應用程式的主題改為 "Theme.AppCompat.NoActionBar",如下所示。
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- 在這里定制你的主題。-->
</style>
并在xml中定義動作欄的自定義布局
uj5u.com熱心網友回復:
我已經解決了這個問題。
我已經解決了這個問題。
val appBarConfiguration = AppBarConfiguration(setOf( R.id.navigation_home, R.id.navigation_messages, R.id.navigation_profile)
setupActionBarWithNavController(navController, appBarConfiguration)
只要從主活動中洗掉上述兩行,你的問題就解決了。
CodePudding
首先,ActionBar是Activities屬性,不是片段。如果你想要一個自定義的動作條,請遵循這個鏈接,https://myandroid.site/custom-toolbar-with-style-in-kotlin-design-colorful-toolbar/
或者
你可以在Activity &中使用默認的ActionBar;創建你自己的布局,看起來像一個動作欄。
隱藏動作條(下面的代碼應該在Activity里面):
if (supportActionBar != null)
supportActionBar?.hide()
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/318385.html
標籤:
