Android自定义标题栏

来源:互联网 发布:酷家乐软件使用方法 编辑:程序博客网 时间:2024/06/14 07:21
public void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//必须设置在setContentView之前。   setContentView(R.layout.activity_main);

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);//custom_title为自定义标题栏布局

}

修改AndroidManifest.xml中该Activity的theme为以下:

其中parent要设为android:Theme或android:Theme.Light,不能设为android:Theme.Holo.Light,否则会报You cannot combine custom titles with other title features错误,可能是因为android:Theme.Holo.Light是用于ActionBar的,跟自定义标题栏有冲突。

<style name="mystyle" parent="android:Theme"><item name="android:windowTitleSize">50dp</item>//改为跟自定义标题栏的高度一样
<item name="android:windowTitleBackgroundStyle">@color/title_bg</item>//改为跟自定义标题栏的背景一样
</style>

0 0
原创粉丝点击