mercredi 29 juin 2016

Android collapsable Toolbar menu icons disappearing

So I've implemented collapsable Toolbar inside my app and in Java class I override onCreateOptionsMenu and onOptionsItemSelected like this:

 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_details, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_share:
                break;
            case R.id.action_addToFavorites:
                break;
        }
        return super.onOptionsItemSelected(item);
    }

And now when I open the activity I can see the menu icons and do stuff with them until the toolbar is colapsed. When user colapses the toolbar the icons disappears.

Second problem, with using the getSupportActionBar().setDisplayHomeAsUpEnabled(true); method i get back button of black color instead of white so now I'm using this method:

tToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_action_navigation_arrow_back));

My question for this problem is how to handle click events for this navigation icon? This icon also disappears when toolbar colapses and leaves the left padding like it's there, but it's not.

Here's my code:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.darioradecic.topmusicandartists.Details">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/MyAppbar"
        android:layout_width="match_parent"
        android:layout_height="256dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <com.android.volley.toolbox.NetworkImageView
                android:id="@+id/imageViewDetailsTopGlobalSongs"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="pin" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/tToolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"

                />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        android:padding="10dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire