Android: Custom Title Bar

后端 未结 5 1375
失恋的感觉
失恋的感觉 2020-11-28 11:08

I have a custom title bar

 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
 setContentView(R.layout.activities);
 getWindow().setFeatureInt(Window.FEATURE         


        
相关标签:
5条回答
  • 2020-11-28 11:20

    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);
    
    }
    
    0 讨论(0)
  • 2020-11-28 11:22

    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.

    0 讨论(0)
  • 2020-11-28 11:28

    First thing why are you using a custom title bar if your app has NoTitleBar? That is silly!

    Needless to say, this is your problem and you must remove that flag.

    Anyhow, the best way to add custom title bar is in xml only. This avoids your app double loading the title bar; which users will see.

    ../res/styles.xml

    <resources>
    
       <style name="AppTheme parent="@style/android:Theme.Light">
          <item name="android:windowNoTitle">false</item>
          <item name="android:windowTitleSize">30dp</item
          <item name="android:windowTitleStyle">@layout/custom_title</item>
       </style>
    
    </resources>
    

    Then you dont need that code about requestAnything.

    0 讨论(0)
  • 2020-11-28 11:29

    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>
    
    0 讨论(0)
  • 2020-11-28 11:29

    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>
    
    0 讨论(0)
提交回复
热议问题