custom)to
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.Dark.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/tl_title"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.Dark.PopupOverlay" /></android.support.design.widget.AppBarLayout>
需要的页面
xml里 <include layout="@layout/toolbar_title"/>
代码中
//设置标题栏,返回键
Toolbar toolbar = (Toolbar) findViewById(R.id.tl_title);
setSupportActionBar(toolbar);
//决定左上角的图标是否可以点击
getSupportActionBar().setHomeButtonEnabled(true);
//显示返回键
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//返回键监听
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// TODO Auto-generated method stub
if(item.getItemId() == android.R.id.home)
{
//按返回键做的操作
finish();
return true;
}
return super.onOptionsItemSelected(item);
}