Android: Custom Title Bar

浪尽此生 提交于 2019-11-26 22:25:30

I had the same issue as you.

The issue is with something you have in your style.

Try this out:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="My_Theme">
        <item name="android:windowTitleSize">35dp</item>
        <item name="android:windowTitleBackgroundStyle">@android:color/black</item>
    </style>
</resources>

This one is the only one for me, which prevents the default-title before my custom title is initiated:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="CustomWindowTitleStyle">
        <item name="android:textColor">@android:color/transparent</item>
    </style>

    <style name="CustomTheme" parent="@android:style/Theme.Holo">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowTitleBackgroundStyle">@android:color/transparent</item>
        <item name="android:windowTitleSize">50dp</item>
        <item name="android:windowTitleStyle">@style/CustomWindowTitleStyle</item>
    </style>

</resources>

you should also check whether customTitle is supported by it or not.

Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);



if (customTitleSupported) {
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);

}

Your App crashes because in your code you calling Title Bar from window features and in other side you disabling it through manifest. Basically You cant do this, its logically incorrect. You need to modify your title bar not to remove it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!