Ответ 1
Я не знаю, как наилучшая практика, но вы можете попробовать это обходное решение, используя пользовательскую кнопку возврата на панели инструментов. Код макета:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/toolbar_back_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:src="@drawable/ic_back" />
<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
и код в действии:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView toolbarTitle = (TextView) findViewById(R.id.toolbar_title);
setSupportActionBar(toolbar);
ImageView backButton = (ImageView) findViewById(R.id.toolbar_back_button);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});