Android的向上箭头不是单纯的返回键,而是返回上一层级,也就是返回该activity的父activity
布局代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:toolbar="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
</LinearLayout>
Java:
public class testActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanted) {
super.onCreate(savedInstanted);
setContentView(R.layout.tres_activity);
Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("记录");
}
}