1.准备Toolbar
先隐藏系统自带的actionbar,在AndroidManifest.xml文件<application>
标签中:
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
(注意此处的Activity应继承AppCompatActivity)
再在布局文件中添加Toolbar,activity_main.xml文件中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.listview_unit4_1.MainActivity">
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary&