Search code examples
androidandroid-actionbarandroid-5.0-lollipoptoolbarandroid-actionbar-compat

Logo disappear from toolbar after while


When I install my app everything seems OK. But when I return after some moment there is no logo in my toolbar. There is only black. It was OK in Android 4.4, but my Galaxy S4 upgraded to Android 5.0.1 and there is this bug in my app. Don't you know why please?

v21\styles.xml

<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>
        <item name="windowActionModeOverlay">true</item>
        <item name="android:statusBarColor">@color/ColorPrimaryDark</item>
</style>

toolbar.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/ColorPrimary"
    app:titleTextAppearance="@style/ToolbarTitle"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:elevation="@dimen/toolbar_elevation">

    <ImageView
        android:id="@+id/tool_logo"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:adjustViewBounds="true"
        android:contentDescription="@string/img_logo"
        android:src="@drawable/logo" />

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

and the same is in drawer header (toolbar OR drawer header is sometimes black ... not both)

drawer_header.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="@color/ColorPrimary">

    <ImageView
        android:id="@+id/navHead"
        android:layout_width="match_parent"
        android:layout_height="@dimen/drawer_header_height"
        android:adjustViewBounds="true"
        android:src="@drawable/logo"
        android:contentDescription="@string/img_logo" />

</LinearLayout>

nothing special in my MainOverview.java

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_list);

mDrawerList = (ListView)findViewById(R.id.navList);

final LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View drawerHeaderView = layoutInflater.inflate(R.layout.drawer_header, null);
mDrawerList.addHeaderView(drawerHeaderView);

toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

Solution

  • I found solution. Black shape displays in action bar because one big-size logo.png was in folder "drawable". Logo must be in drawable-mdpi/hdpi/etc. in equal sizes (48dp/56dp height, depends on android version). I don't know why Android 5.0.1 on Galaxy S4 doesn't downsize the picture correct like emulators or real 4.4.2 device. But now it seems ok.