Yeah as you can see above I get the mentioned Error. But I'm 100% sure the Activity's theme doesn't have an Action Bar. I'm trying to get de Toolbar working but every time I open the Activity the App crashes.
Here is the full Stacktrace
2019-12-10 22:32:54.796 27068-27068/com.simplemobiletools.studentcalendarpaid.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.simplemobiletools.studentcalendarpaid.debug, PID: 27068
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.simplemobiletools.studentcalendarpaid.debug/com.simplemobiletools.studentcalendarpaid.activities.MainActivity}: 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 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3047)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3182)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1916)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
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:345)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)
at com.simplemobiletools.studentcalendarpaid.activities.MainActivity.toolBar(MainActivity.kt:192)
at com.simplemobiletools.studentcalendarpaid.activities.MainActivity.onCreate(MainActivity.kt:178)
at android.app.Activity.performCreate(Activity.java:7149)
at android.app.Activity.performCreate(Activity.java:7140)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3027)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3182)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1916)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-12-10 22:32:54.800 27068-27068/com.simplemobiletools.studentcalendarpaid.debug W/OPDiagnose: getService:OPDiagnoseService NULL
2019-12-10 22:32:54.817 27068-27068/com.simplemobiletools.studentcalendarpaid.debug I/Process: Sending signal. PID: 27068 SIG: 9
Here you can see the main Activity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(com.simplemobiletools.studentcalendarpaid.R.layout.activity_main)
appLaunched(com.simplemobiletools.studentcalendarpaid.BuildConfig.APPLICATION_ID)
prefs = getSharedPreferences("com.simplemobiletools.studentcalendarpro", MODE_PRIVATE);
prefs = getSharedPreferences("com.simplemobiletools.studentcalendarpro", MODE_PRIVATE);
/*
prefs = getSharedPreferences("com.simplemobiletools.studentcalendarpro", MODE_PRIVATE)
if (prefs!!.getBoolean("firstrun", true)) {
val h = Intent(this@GradeMainActivity, OnBoardingActivity::class.java)
startActivity(h)
prefs!!.edit().putBoolean("firstrun", false).apply();
}
*/
drawerLayout = findViewById(com.simplemobiletools.studentcalendarpaid.R.id.drawer_layout)
navigationView = findViewById(com.simplemobiletools.studentcalendarpaid.R.id.nav_view)
navigationView!!.bringToFront()
navigationView!!.setNavigationItemSelectedListener(this)
/*
val toggle = ActionBarDrawerToggle(this, drawerLayout, toolbar,
R.string.navigation_draw_open, R.string.navigation_draw_close)
drawerLayout!!.addDrawerListener(toggle)
toggle.syncState()
*/
/*
checkWhatsNewDialog()
calendar_fab.beVisible()
*/
calendar_fab.setOnClickListener {
launchNewEventIntent(currentFragments.last().getNewEventDayCode())
}
storeStateVariables()
if (resources.getBoolean(com.simplemobiletools.studentcalendarpaid.R.bool.portrait_only)) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
if (!hasPermission(PERMISSION_WRITE_CALENDAR) || !hasPermission(PERMISSION_READ_CALENDAR)) {
config.caldavSync = false
}
if (config.caldavSync) {
refreshCalDAVCalendars(false)
}
swipe_refresh_layout.setOnRefreshListener {
refreshCalDAVCalendars(false)
}
if (!checkViewIntents()) {
return
}
if (!checkOpenIntents()) {
updateViewPager()
}
checkAppOnSDCard()
updateViewPager()
toolBar()
}
private fun toolBar() {
val tb = findViewById<Toolbar>(R.id.myToolbar)
tb.setTitle("Android Toolbar");
// tb.setTitleTextAppearance(this, R.style.toolbarTitle);
// tb.setSubtitle("My SubTitle");
// tb.setSubtitleTextAppearance(this, R.style.toolbarSubTitle);
// tb.setContentInsetsAbsolute(0, 54); // Best used when setting a Logo
// tb.setContentInsetsRelative(0, 54); // Best used when setting a Logo
// tb.setLogo(R.mipmap.ic_launcher);
setSupportActionBar(tb)
if (getSupportActionBar() != null) {
// This sets a shadow underneath the Toolbar
getSupportActionBar()?.setElevation(8F);
}
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
// Handle navigation view item clicks here.
// here is the main place where we need to work on.
val id = item.itemId
when (id) {
com.simplemobiletools.studentcalendarpaid.R.id.nav_calendar -> {
val h = Intent(this@MainActivity, MainActivity::class.java)
startActivity(h)
}
/*
com.simplemobiletools.studentcalendarpro.R.id.nav_account -> {
val l = Intent(this@GradeMainActivity, AccountActivity::class.java)
startActivity(l)
}*/
com.simplemobiletools.studentcalendarpaid.R.id.nav_todo -> {
/*Falls ich Fragments gebrauchen will
//val fragment = ToDoFragment()
//displayFragment(fragment)
//supportFragmentManager.beginTransaction().add(R.id.fragments_holder, fragment).commitNow()
*/
val m = Intent(this@MainActivity, TodoActivity::class.java)
startActivity(m)
}
R.id.nav_grades -> {
val i = Intent(this@MainActivity, AddGradeActivity::class.java)
startActivity(i)
}
com.simplemobiletools.studentcalendarpaid.R.id.nav_info -> {
val k = Intent(this@MainActivity, com.simplemobiletools.studentcalendarpaid.activities.InfoActivity::class.java)
startActivity(k)
}
com.simplemobiletools.studentcalendarpaid.R.id.nav_overview -> {
val j = Intent(this@MainActivity, ViewListContents::class.java)
startActivity(j)
}
}// this is done, now let us go and intialise the home page.
// after this lets start copying the above.
// FOLLOW MEEEEE>>>
val drawer = findViewById<View>(com.simplemobiletools.studentcalendarpaid.R.id.drawer_layout) as DrawerLayout
drawer.closeDrawer(GravityCompat.START)
return true
updateViewPager()
}
private fun displayFragment(fragment: Fragment) {
supportFragmentManager
.beginTransaction()
.replace(R.id.fragments_holder, fragment)
.commit()
}
and here my styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme2" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar" >
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="TextAppearance44">
<item name="android:textColor">#ffff</item>
<item name="android:textSize">16sp</item>
</style>
<style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AudioFileInfoOverlayText">
<item name="android:paddingLeft">4px</item>
<item name="android:paddingBottom">4px</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">12sp</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">1</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="DayView">
<item name="android:gravity">center</item>
<item name="android:textSize">@dimen/day_text_size</item>
<item name="android:fontFamily">sans-serif-light</item>
</style>
<style name="MetaView" parent="DayView">
<item name="android:textStyle">bold</item>
<item name="android:textSize">@dimen/meta_text_size</item>
</style>
<style name="WeekNumberStyle">
<item name="android:textStyle">bold</item>
<item name="android:gravity">top|center_horizontal</item>
<item name="android:textSize">@dimen/day_monthly_text_size</item>
<item name="android:textColor">@color/default_text_color</item>
<item name="android:fontFamily">sans-serif-light</item>
</style>
<style name="ArrowStyle">
<item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>
</style>
<style name="MonthStyle">
<item name="android:background">?android:attr/selectableItemBackground</item>
</style>
</resources>
and here the important thing in my Main Application
toolBar()
}
private fun toolBar() {
val tb = findViewById<Toolbar>(R.id.myToolbar)
tb.setTitle("Android Toolbar");
// tb.setTitleTextAppearance(this, R.style.toolbarTitle);
// tb.setSubtitle("My SubTitle");
// tb.setSubtitleTextAppearance(this, R.style.toolbarSubTitle);
// tb.setContentInsetsAbsolute(0, 54); // Best used when setting a Logo
// tb.setContentInsetsRelative(0, 54); // Best used when setting a Logo
// tb.setLogo(R.mipmap.ic_launcher);
setSupportActionBar(tb)
if (getSupportActionBar() != null) {
// This sets a shadow underneath the Toolbar
getSupportActionBar()?.setElevation(8F);
}
}
Here is also my Manifest.xml
<activity
android:name="com.simplemobiletools.studentcalendarpaid.activities.MainActivity"
android:theme="@style/AppTheme2"
android:launchMode="singleTask">
<meta-data
android:name="android.app.default_searchable"
android:resource="@xml/searchable"/>
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:mimeType="text/x-vcalendar"/>
<data android:mimeType="text/calendar"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="time/epoch"/>
<data android:host="com.android.calendar"/>
<data android:scheme="content"/>
</intent-filter>
<intent-filter
tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="vnd.android.cursor.item/event"/>
</intent-filter>
</activity>
As you can see I set the AppTheme to NoActionBar and still get this Error: 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.
Does somebody know the answer?