>

여기에 문제가 있습니다.이 링크에서 얻는 CollapsingToolbarBehavior를 사용하고 있습니다. https://github.com/saulmm/CoordinatorBehaviorExample . 그러나 축소시 툴바에서 아이콘을 클릭하면 죽은 링크와 같습니다. OnOptionsItemSelected를 호출하지 않아도 다른 레이아웃과 스택 또는 무엇입니까?

주요 활동 코드는 다음과 같습니다.

   mToolbar = (Toolbar) findViewById(R.id.main_toolbar);
    mToolbar.inflateMenu(R.menu.edit);
    @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.edit, menu);
            return true;
        }
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            int id = item.getItemId();
            Log.d("in","hahhaah");
            if(id == R.id.btn_back_edit){
                onBackPressed();
                return true;
            }
            if (id == R.id.btn_edit) {
                invalidateOptionsMenu();
                Intent intent = new Intent(SettingProfileActivity.this, SettingProfileActivityOn.class);
                startActivity(intent);
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
        @Override
        public void onBackPressed() {
            super.onBackPressed();
            Intent intent = new Intent(SettingProfileActivity.this,MainActivity.class);
            intent.putExtra("LoadFragment", "settings");
            startActivityForResult(intent,0);
            finish();
        }

레이아웃 코드는 다음과 같습니다.

<?xml version="1.0" encoding="utf-8"?>
<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:ignore="RtlHardcoded">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/main.appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main.collapsing"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
            <ImageView
                android:id="@+id/main.imageview.placeholder"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:scaleType="centerCrop"
                android:background="@color/colorPrimary"
                android:tint="#11000000"
                app:layout_collapseMode="parallax" />
            <FrameLayout
                android:id="@+id/main.framelayout.title"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_gravity="bottom|center_horizontal"
                android:background="@color/colorPrimary"
                android:orientation="vertical"
                app:layout_collapseMode="parallax">
                <LinearLayout
                    android:id="@+id/main.linearlayout.title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:orientation="vertical">
                    <TextView
                        android:id="@+id/sebelum.anim"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="bottom|center"
                        android:fontFamily="@font/raleway_medium"
                        android:layout_marginTop="30dp"
                        android:text="Robert"
                        android:textColor="@android:color/white"
                        android:textSize="24sp" />
                    <TextView
                        android:id="@+id/jenis_usaha"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:fontFamily="@font/raleway_medium"
                        android:layout_gravity="center_horizontal"
                        android:gravity="bottom|center"
                        android:layout_marginTop="6dp"
                        android:layout_marginBottom="5dp"
                        android:text="Robert"
                        android:textColor="@android:color/white"
                        android:textSize="20sp" />
                </LinearLayout>
            </FrameLayout>
        </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:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <android.support.constraint.ConstraintLayout 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:id="@+id/cl"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="0dp">
            <include
                android:id="@+id/tool_bar"
                layout="@layout/custom_toolbar">
            </include>
            <View
                android:id="@+id/view2"
                android:layout_width="0dp"
                android:layout_height="52dp"
                android:background="@color/placeholder_bg"
                app:layout_constraintBottom_toTopOf="@+id/text_nama_profile"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0"
                app:layout_constraintVertical_chainStyle="packed" />
            <TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginBottom="16dp"
                android:layout_marginEnd="24dp"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:layout_marginStart="24dp"
                android:layout_marginTop="16dp"
                android:fontFamily="@font/raleway_semibold"
                android:text="PERSONAL DETAILS"
                android:textAlignment="center"
                android:textAppearance="@android:style/TextAppearance.Medium"
                android:textColor="#6b6c6d"
                app:layout_constraintBottom_toBottomOf="@+id/view2"
                app:layout_constraintEnd_toEndOf="@+id/view2"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="@+id/view2"
                app:layout_constraintTop_toTopOf="@+id/view2"
                app:layout_constraintVertical_bias="0.0" />
            <TextView
                android:id="@+id/text_nama_profile"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginBottom="16dp"
                android:layout_marginEnd="8dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="8dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:fontFamily="@font/raleway_medium"
                android:text="Robert"
                android:textAppearance="@android:style/TextAppearance.Medium"
                app:layout_constraintBottom_toTopOf="@+id/text_jk_profile"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view2" />
<View
                android:id="@+id/batas6"
                android:layout_width="0dp"
                android:layout_height="1.75dp"
                android:layout_marginTop="9dp"
                android:background="@color/placeholder_bg"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/text_alamat_profile"
                app:layout_constraintVertical_bias="0.0" />
        </android.support.constraint.ConstraintLayout>
    </android.support.v4.widget.NestedScrollView>
    <android.support.v7.widget.Toolbar
        android:id="@+id/main.toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        app:layout_anchor="@id/main.framelayout.title"
        app:theme="@style/ThemeOverlay.AppCompat.Dark"
        app:title="">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <Space
                android:layout_width="@dimen/image_final_width"
                android:layout_height="@dimen/image_final_width" />
            <TextView
                android:id="@+id/main.textview.title"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="8dp"
                android:gravity="center_vertical"
                android:text="Robert"
                android:textColor="@android:color/white"
                android:textSize="20sp" />
        </LinearLayout>
    </android.support.v7.widget.Toolbar>
    <de.hdodenhof.circleimageview.CircleImageView
        android:layout_width="@dimen/image_width"
        android:layout_height="@dimen/image_width"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/person"
        app:finalHeight="@dimen/image_final_width"
        app:finalYPosition="2dp"
        app:civ_border_color="@android:color/white"
        app:civ_border_width="2dp"
        app:layout_behavior=".AvatarImageBehavior"
        app:startHeight="2dp"
        app:startToolbarPosition="2dp"
        app:startXPosition="2dp"
        />
</android.support.design.widget.CoordinatorLayout>

메뉴 파일의 코드입니다 :

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/btn_back_edit"
        android:title=""
        app:showAsAction="always"
        android:icon="@drawable/ic_back"
        />
    <item
        android:id="@+id/btn_edit"
        android:title=""
        app:showAsAction="always"
        android:icon="@drawable/ic_edit"
        />
</menu>

custom_toolbar 레이아웃은 다음과 같습니다.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/toolbar">
</android.support.v7.widget.Toolbar>

  • 답변 # 1

    여기서 문제는 툴바의 inflateMenu 를 사용하고 있다는 사실과 관련이 있습니다.  AppCompactActivity의 setSupportActionBar 를 사용하지 않는 메소드 .

    이 방법에는 여러 가지가 있습니다. 툴바의 setOnMenuItemClickListener 를 사용하는 것이 좋습니다 .

관련 자료

  • 이전 javascript - 주어진 길이의 배열을 초기화하는 템플릿 리터럴
  • 다음 angular - 하위 구성 요소 필드가 유효하지 않은 경우 상위 구성 요소 양식 제출 단추를 비활성화하는 방법