Bạn có thể thêm nút 'lên' của riêng mình trong thanh công cụ, sau khi tất cả chỉ là một ViewGroup.
Bạn có thể tùy chỉnh thanh công cụ nhiều như bạn muốn, trong toolbar.xml của bạn, hoặc bất cứ nơi nào bạn đã xác định android.support.v7.widget.Toolbar trong cách bố trí của bạn thêm của bạn 'lên' nút như đưa ra dưới đây:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/color_toolbar"
android:layout_width="match_parent">
<ImageButton
android:id="@+id/upButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="uphandler"
android:src="@drawable/backbutton"
android:layout_gravity="end"/>
</android.support.v7.widget.Toolbar>
Bây giờ, xác định uphandler chức năng trong hoạt động của bạn để nghe nút này lên:
public void uphandler(View v){
this.finish(); // This will kill current activity, and if previous activity is still opened in background, it will come in front.
}
Nguồn
2014-12-17 21:19:48
Sử dụng this.finish() là một mẫu chống, vì biểu tượng "lên" sẽ đưa người dùng đến cha mẹ phân cấp trong ứng dụng của bạn - không nhất thiết là màn hình cuối cùng mà họ đã xem: https://material.google.com /patterns/navigation.html#navigation-up-back-buttons – gsysko