Android:自定义标题栏
我有一个自定义标题栏
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activities);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
,基本上工作正常。问题是,在调用上面的代码之前,都会显示默认标题栏。我根本不想要标题栏,换句话说,在我的标题栏出现之前,不会出现任何标题。
将其添加到清单中:
<application android:theme="@android:style/Theme.NoTitleBar">
导致强制关闭。我的清单看起来像这样,
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:theme="@style/My_Theme">
我需要 my_Theme 的地方,因为它设置了背景颜色,在我的客户主题中设置背景颜色会导致我的彩色背景周围出现灰色区域。因此,即使没有强制关闭,我也不确定无标题是否有帮助。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我和你有同样的问题。
问题出在你的风格上。
试试这个:
I had the same issue as you.
The issue is with something you have in your style.
Try this out:
这是我唯一的一个,它可以在我的自定义标题启动之前阻止默认标题:
This one is the only one for me, which prevents the default-title before my custom title is initiated:
首先,如果您的应用程序有 NoTitleBar,为什么还要使用自定义标题栏?那太愚蠢了!
不用说,这是您的问题,您必须删除该标志。
无论如何,添加自定义标题栏的最佳方法是仅使用 xml。这可以避免您的应用程序重复加载标题栏;用户将会看到哪些内容。
../res/styles.xml
那么您不需要有关 requestAnything 的代码。
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
Then you dont need that code about requestAnything.
您还应该检查它是否支持 customTitle。
you should also check whether customTitle is supported by it or not.
您的应用程序崩溃是因为在您的代码中您从窗口功能调用标题栏,而在另一侧您通过清单禁用它。基本上你不能这样做,它在逻辑上是错误的。
您需要修改标题栏而不是删除它。
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.