首先第一步建一个attrs 在value 里面
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="zhangTopbar">
<attr name="zhang_leftBackgroud" format="reference"/>
<attr name="zhang_rightBackgroud" format="reference"/>
<attr name="titleText" format="string"/>
<attr name="titleColor" format="color"/>
<attr name="titleSize" format="dimension"/>
</declare-styleable>
</resources>
自定义view布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff00">
<Button
android:id="@+id/leftButton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"