第一种:include
1.设置一个需要的xml布局
2.activity_main.xml中引用这个布局
<include layout="@layout/titlebat"/>
3.AndroidManifest.xml中
将:android:theme="@style/APPTheme">改成
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
第二种方法:
1.先在values下新建一个attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--标题中自定义设置的东西-->
<declare-styleable name="CustomTitleBar">
<attr name="left_btn_drawable" format="reference|integer"/>
<attr name="right_btn_drawable" format="reference|integer"/>
<attr name="middle_text_title" format="string"/>
<attr name="title_background_color" format="reference|color"/>
</declare-styleable>
</resources>
2.在layout中设置布局,titlebar.xml
<RelativeLayout xmlns:android="http://schem