如何隐藏标题栏,而应用程序加载并显示它时,它完成加载? [英] How to hide the title bar while application is loading and show it when it finishes loading?

查看:220
本文介绍了如何隐藏标题栏,而应用程序加载并显示它时,它完成加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用自定义标题栏的应用程序。然而,当我的应用程序启动时,我注意到默认的标题栏中显示的时间短暂。我的问题是,我不希望显示默认的标题栏,而我的应用程序加载。如何隐藏标题栏,而我的应用程序加载,这样不会有一丝的,然后将其事后证明?

到目前为止,我尝试以下解决方案,但没有工作过:

  • 隐藏在XML中的标题栏,然后将在code中的自定义标题栏。 (中遇到的问题:我收到一条错误信息,说:你不能将自定义标题与其他标题功能)

在XML:

 <项目名称=机器人:windowNoTitle>真< /项目>
 

在onCreate方法:

  requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
// ...一些code到这里
。getWindow()setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title_header);
 

  • 设置的XML为0。标题栏的大小,然后通过code以后改变它的大小。 (遇到问题:?我不知道如何设置的标题栏code尺寸是否有可能我想getWindow()setAttributes()和getWindow()的setLayout(),但他们两人没。牛逼的工作。)

在XML:

 <项目名称=机器人:windowTitleSize> 30dp< /项目>
 

  • 修改windowTitleBackgroundStyle并设置一个透明的可绘制作为背景。 (遇到问题:标题栏的内容变得不可见的,但标题栏下方的线仍是可见的)

在XML:

 <! - 使用windowTitleBackgroundStyle风格 - >
<项目名称=机器人:背景> @可绘制/透明< /项目>
 

解决方案

一些解释你遇到了什么,希望他们帮助引导你的方向你满意。

您已经看到了你的主题是用来产生你在活动加载见。这是怎么回事是系统生成基于您的活动的主题临时/加载窗口中指定您的清单,而你的进程仍在启动。您的code甚至可能不会运行着呢,你自己的活动都会有一个不同的窗口。这是显著因为一些设置被锁定在曾经窗口的装饰已经建立,但实际上你这里有两次机会。尚未创建的活动使用的窗口然而,当你看到这个加载状态。

设置在你的主题没有标题是行不通的,因为其映射到窗口功能 Window.FEATURE_NO_TITLE 。这占主导地位比任何其他的标题窗口的功能,你可以要求,一旦一个功能要求你不能取消请求或无论是否装饰已被初始化删除它。

作为你的主题的一部分,标题的大小是给你predictable问题。主题属性不能改变。然而,该主题的活动正在使用的可以的之前,你的窗口的装饰已被初始化改变。您可以在清单为将加载过程中所用的活动指定一个主题,并使用 setTheme 您的活动交换了出来。 (最好的地方可能是的setContentView,在那里,否则你将要求窗口功能之前的onCreate。)

机会是下面你所看到的标题栏中的线是 安卓windowContentOverlay - 用于从对内容的标题栏提供阴影的绘制。在大多数设备这个影子的顶部边缘可能会出现在标题栏区域下方一行。你可以将其设置为 @null 摆脱的阴影完全,如果你想要的。

I have an application which uses a custom title bar. However, when my application launches, I noticed that the default title bar is shown for a brief period of time. My problem is I don't want to show the default title bar while my application is loading. How do I hide the title bar while my application is loading so that there will be no hint of it and then show it afterwards?

So far, I tried the following solutions but none have worked:

  • Hide the title bar in XML and then set the custom title bar in code. (Problem encountered: I received an error message saying: "You cannot combine custom titles with other title features".)

In XML:

<item name="android:windowNoTitle">true</item>

In onCreate method:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//... some code goes here
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_header);

  • Set the size of the title bar in XML to 0. Then change it's size via code later. (Problem encountered: I don't know how to set the size of title bar in code. Is it possible? I tried getWindow().setAttributes() and getWindow().setLayout() but both of them didn't worked.)"

In XML:

<item name="android:windowTitleSize">30dp</item>

  • Modify windowTitleBackgroundStyle and set a transparent drawable as background. (Problem encountered: The content of the title bar became invisible but a line below the title bar is still visible.)

In XML:

<!-- style used by windowTitleBackgroundStyle -->
<item name="android:background">@drawable/transparent</item>

解决方案

Some explanations for what you've encountered, hopefully they help lead you in a direction you're happy with.

You've already seen that your theme is used to generate what you see during activity loading. What's happening is the system is generating a temporary/loading window based on your activity's theme as specified in your manifest while your process is still starting up. Your code may not even be running yet, and your own activity will have a different window. This is significant because a number of settings become locked in once the window's decor has been created, but you actually have two chances here. The window your activity uses hasn't been created yet when you see this loading state.

Setting no title in your theme isn't working because it maps to the window feature Window.FEATURE_NO_TITLE. This dominates over any other title window features you may request and once a feature is requested you can't un-request or remove it regardless of whether decor has been initialized yet.

As part of your theme, the title size is giving you predictable issues. Theme attributes can't be changed. However, which theme your activity is using can be changed before your window decor has been initialized. You can specify one theme in your manifest for the activity that will be used during loading and swap it out using setTheme on your activity. (Best place is probably in onCreate before setContentView, where you would otherwise request window features.)

Chances are the line below the title bar you're seeing is the android:windowContentOverlay - the drawable used to supply the drop shadow from the title bar over the content. On most devices the top edge of this shadow would probably appear as a line below the title bar area. You can set this to @null to get rid of the shadow entirely if you want.

这篇关于如何隐藏标题栏,而应用程序加载并显示它时,它完成加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆