我正在為我的 Activity 實現一個折疊工具欄。我想知道是否可以設置和導航箭頭到折疊工具欄布局并設置 Onclick 偵聽器,這將帶我到以前的活動。我可以僅使用給出的工具欄布局成功實現此類功能 <android.support.v7.widget.Toolbar android:id="@+id/toolbar_details" android:title="Disclaimer" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#fff" android:minHeight="56dp" android:layout_alignParentTop="true" app:theme="@style/ThemeOverlay.AppCompat.Light"/>在 OnCreate 方法中,我使用 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_details); setSupportActionBar(toolbar); tutorProfile.this.setTitle(getIntent().getStringExtra("My Dashboard")); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent check = new Intent(CurrentActivity.this, PreviousActivity.class); startActivity(check); finish(); } });但是在Collpasing toolbar layout中如何實現同樣的功能。這是xml布局<android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing" android:layout_width="match_parent" android:layout_height="150dip" android:fitsSystemWindows="true" app:contentScrim="#784242" app:expandedTitleMarginBottom="20dp" app:expandedTitleMarginEnd="64dp" app:expandedTitleMarginStart="48dp" app:layout_scrollFlags="scroll|exitUntilCollapsed">我搜索了幾分鐘,但找不到任何解決方案。提前感謝您的幫助。
1 回答

呼喚遠方
TA貢獻1856條經驗 獲得超11個贊
你為什么不簡單地使用toolbar.setDisplayHomeAsUpEnabled(true)然后
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
finish()
return true
}
}
return super.onOptionsItemSelected(item)
}
添加回答
舉報
0/150
提交
取消