问题:
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:581)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:183)
at com.example.mykotlin1.AddUpdateDishActivity.setupActionBar(AddUpdateDishActivity.kt:22)
at com.example.mykotlin1.AddUpdateDishActivity.onCreate(AddUpdateDishActivity.kt:17)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
问题描述:通过如下代码给activity设置actionbar
private fun setupActionBar(){
setSupportActionBar(mBinding.toolbarAddDishActivity)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
mBinding.toolbarAddDishActivity.setNavigationOnClickListener {
onBackPressed()
}
}
mainfest中activity没有设置theme,默认是有actionbar的
原因:使用代码设置actionbar之前,先设置activity的theme为无actionbar,然后再调用代码
解决办法:
设置activity为noactionbar
自定义theme:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)