需要设置一些代码:
private void setCustomTitle() {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.customtitle);
}
另外要引用自己定义的样式:
<style name="CustomizedWindowTitleBackground">
<item name="android:background">#044BF6</item>
</style>
<style name="titlebarstyle" parent="android:Theme">
<item name="android:windowTitleSize">48dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomizedWindowTitleBackground</item>
</style>
转载于:https://www.cnblogs.com/gcczhongduan/p/5049210.html