【发布时间】:2020-01-11 19:14:38
【问题描述】:
我创建了一个没有操作栏的自定义主题样式:
<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>
</style>
在我的清单中,我使用了这种风格:
<application
android:largeHeap="true"
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
这样我的所有活动中都没有操作栏。但是我希望它只出现在某些活动中。我尝试添加代码:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val layoutInflater: LayoutInflater = LayoutInflater.from(this)
val view: View = layoutInflater.inflate(R.layout.activity_edit_profile, null)
setContentView(view)
supportActionBar?.show()
但是操作栏没有显示,我认为原因是主题不支持操作栏。我只想在少数活动中显示操作栏,即使如此,我是否应该创建一个带有操作栏的主题并在大多数活动中以编程方式隐藏它?
【问题讨论】:
标签: android kotlin android-actionbar