1.android自定义Titlebar要在AndroidManifest配置文件的<application>中添加android:theme然后设置你重写的style:
android:theme="@style/test"
2. 在styles xml文件中添加style
<style name="test" parent="android:Theme"> //一定要继承原有的style
<item name="android:windowTitleSize">45dp</item>// 设置titlebar的height大小
<item name="android:windowTitleBackgroundStyle">@style/test1</item>//设置背景颜色
</style>
3. 在titlebar中定义自己的布局
//启用windows的扩展忒性,自定义标题(一定要放在setContentView前面)
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);//
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.test);//设置自己的布局
4.加深titlebar中有按钮需要实现事件监听可以直接获取button控件
setBtn=(Button)findViewById(R.id.settingBt);