我有一個導航抽屜,它的第一個片段中有一個新聞頁面,用戶單擊按鈕查看整個新聞,並在那一刻它進入另一個片段。如何在片段中實現向後箭頭
我想知道我是如何實現一個箭頭返回到前一個片段,而不是打開導航抽屜的圖標。
我從來沒有與此合作過,我不知道。
這是我在MainActivity
appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout);
toolbar = (Toolbar) findViewById(R.id.toolbar);
//toolbar title
toolbar.setTitle(null);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
// Toolbar logo
logoToolbar = (ImageView) findViewById(R.id.logoToolbar);
logoToolbar.setImageResource(R.drawable.newstoolbar);
工具欄當MainFragment
newsMore.get(0).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
newsFrag1 newsFragment1 = new newsFrag1();
ft.replace(R.id.fragment_container, newsFragment1);
ft.commit();
}
});
用戶單擊「更多」然後它去newsFrag1,我想有回箭頭
我的工具欄XML
<?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"
android:fitsSystemWindows="true"
tools:context="studio.com.archeagemanager.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:background="?attr/colorPrimary"
android:gravity="center_vertical"
android:minHeight="56dp"
android:weightSum="1"
app:popupTheme="@style/AppTheme.PopupOverlay">
<ImageView
android:id="@+id/logoToolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="56dp">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
分享一些代碼... –
檢查了這一點https://stackoverflow.com/questions/5448653/how-to-implement-onbackpressed-in-fragments –
什麼是您的工具欄的XML? –