Thursday, 17 January 2019

Custom SupportActionBar looks different after redisplayed

I'm trying to build a Single Activity App and using a custom SupportActionBar in my Activity. The other Views are all Fragments.

My custom SupportActionBar looks like this:

Correct SupportActionBar

Now I have the case that I have to display a video in fullscreen mode in a Fragment. Therefore I'm just calling the hide function of the SupportActionBar:

override fun onResume() {
super.onResume()
(activity as  MainActivity).supportActionBar!!.hide()}

That works fine, but when I want to display the bar again after the video is finished the bar looks not the same.

Wrong SupportActionBar

In my Fragment I'm calling the show function from SupportActionBar and the initToolbar function of the MainActivity:

override fun onStop() {
    super.onStop()
    (activity as MainActivity).supportActionBar!!.show()
    (activity as MainActivity).initToolbar()
}

And here is the initToolbar method from my Activity:

fun initToolbar() {
    setSupportActionBar(toolbar_all_custombar)
    supportActionBar!!.setDisplayShowTitleEnabled(false)
    supportActionBar!!.setIcon(R.drawable.ic_launcher)
}

The toolbar layout:

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_all_custombar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:titleTextAppearance="@style/AppTheme.TitleTextStyle"
app:titleTextColor="@color/textColorPrimary">

<TextView
    android:id="@+id/toolbar_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/all_toolbar_title"
    android:textColor="@android:color/white"
    android:textStyle="bold|italic"/>

</android.support.v7.widget.Toolbar>

I don't get it why my bar looks different after showing it again. What is the cause of this behaviour?



from Custom SupportActionBar looks different after redisplayed

No comments:

Post a Comment