11

I have a custom title bar

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

Which works basically fine. The problem is that until the above code is called the default title bar is shown. I don't want a title bar there at all, in other words before mine shows up no title shall show up.

Adding this to the manifest:

<application android:theme="@android:style/Theme.NoTitleBar">

leads to a force close. My manifest looks like this

<application android:icon="@drawable/icon" android:label="@string/app_name"
    android:theme="@style/My_Theme">

Where I need my_Theme since it sets the background color, setting the background color in my customer theme leads to a gray area around my colored backround. So even without the force close I am not sure if the no title will help.

Any idea?

4

5 回答 5

14

我和你有同样的问题。

问题在于你的风格。

试试这个:

<?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>
于 2010-07-01T12:28:48.580 回答
2

这对我来说是唯一的一个,它可以在我的自定义标题启动之前阻止默认标题:

<?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>
于 2013-11-27T12:47:43.197 回答
0

您还应该检查它是否支持 customTitle。

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



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

}
于 2015-03-12T08:52:33.580 回答
0

首先,如果您的应用程序有 NoTitleBar,为什么要使用自定义标题栏?那太傻了!

不用说,这是您的问题,您必须删除该标志。

无论如何,添加自定义标题栏的最佳方式是仅在 xml 中。这样可以避免您的应用重复加载标题栏;哪些用户会看到。

../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>

那么你就不需要关于 requestAnything 的代码了。

于 2019-08-19T17:29:51.170 回答
-1

您的应用程序崩溃,因为在您的代码中您从窗口功能调用标题栏,而在另一方面您通过清单禁用它。基本上你不能这样做,它在逻辑上是不正确的。您需要修改标题栏而不是删除它。

于 2013-09-18T11:20:31.007 回答