Меню CollapsingToolbarLayout и индикатор вверх

Я использую новый дизайн Android CollapsingToolbarLayout. Тем не менее, я не могу заставить меню появиться. Также не появляется индикатор homeasup.

Может ли кто-нибудь указать мне в правильном направлении? Или это просто невозможно?

ИЗМЕНИТЬ

Итак, мне наконец-то вернули ноутбук. Вот код.

Активность

public class CheeseDetailActivity extends AppCompatActivity {

public static final String EXTRA_NAME = "cheese_name";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);

    Intent intent = getIntent();
    final String cheeseName = intent.getStringExtra(EXTRA_NAME);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);



    CollapsingToolbarLayout collapsingToolbar =
            (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle(cheeseName);


    loadBackdrop();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
    }
    return super.onOptionsItemSelected(item);
}

private void loadBackdrop() {
    final ImageView imageView = (ImageView) findViewById(R.id.backdrop);
    Glide.with(this).load(Cheeses.getRandomCheeseDrawable()).centerCrop().into(imageView);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_player, menu);

    return true;
}

}

Расположение

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/detail_backdrop_height"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="24dp"
            app:expandedTitleMarginEnd="48dp">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_marginTop="@dimen/toolbar_top_margin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin"
                app:borderWidth="@dimen/fab_border" />

        </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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="24dp">

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/card_margin">

                <LinearLayout
                    style="@style/Widget.CardContent"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Info"
                        android:textAppearance="@style/TextAppearance.AppCompat.Title" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/cheese_ipsum" />

                </LinearLayout>

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

        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

Меню

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >
    <item android:id="@+id/action_settings" android:title="@string/action_settings"
        android:orderInCategory="100" app:showAsAction="ifRoom" />
</menu>

Как мы видим, нет ни переполнения, ничего. Но когда я нажимаю физическую кнопку меню, меню появляется нормально.

Расширенная панель инструментовСвернутая панель инструментов Меню при нажатии физической кнопки


person frostymarvelous    schedule 29.06.2015    source источник
comment
Какой код вы сейчас используете и что конкретно вы видите?   -  person Bryan Herbst    schedule 29.06.2015
comment
К сожалению, сейчас я не могу опубликовать код, но я фактически клонировал приложение сыроварни.   -  person frostymarvelous    schedule 29.06.2015
comment
@Tanis.7x Я добавил код и изображения   -  person frostymarvelous    schedule 02.07.2015


Ответы (1)


Так что, наверное, я действительно был очень глуп. Я использовал неправильное поле для панели инструментов. android:layout_marginTop="@dimen/toolbar_top_margin"

Поля должны были быть -48dp, но я использовал 48dp.

У меня такое было в габаритах. Я забыл изменить на toolbar_top_margin_neg после рефакторинга.

<dimen name="toolbar_top_margin">48dp</dimen>
<dimen name="toolbar_top_margin_neg">-48dp</dimen>
person frostymarvelous    schedule 02.07.2015