出现我的自定义标题栏之前显示的默认标题栏

时间:2015-09-30 03:04:26

标签: android android-actionbar android-titlebar custom-titlebar

我'开发一个Android应用程序,我需要使用我的自定义标题栏使用图片和两个按钮。问题是,当我启动我的应用程序时,在我的自定义标题栏出现之前的1或2秒内,有一个丑陋的默认值与我的应用程序"显示。目标API的最小值为15。

在堆栈溢出时找到的所有答案都没有用,或者成功使它消失但是对我的自定义标题栏也一样。

以下是我从我的活动中调用它的方式:

supportRequestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.topbarclassic);

由于我的第一个视图是片段,所以我不会调用SetContentView

这是我的自定义styles.xml:

<resources>

    <style name="theme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowTitleSize">50dp</item>
        <item name="android:windowNoTitle">false</item>
    </style>

</resources>

我的自定义标题栏再次正常工作。我只需要摆脱应用程序启动时快速显示的默认值。非常感谢!

2 个答案:

答案 0 :(得分:1)

如果您使用此样式,则活动将在没有操作栏的情况下加载

<style name="theme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

然后您应该使用工具栏来设置操作栏。例如:

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize" />

</RelativeLayout>

然后在您的活动中,您可以像这样设置操作栏:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(...);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

别忘了在AndroidManifest.xml中设置它们

    <activity
        android:name=".path.MyActivity"
        android:theme="@style/theme"/>

答案 1 :(得分:0)

如果使用Modge关于启动画面的链接找到了我的问题的解决方法。

它本身并没有解决问题,但仍然是一个很好的解决方法。

我创建了一个负责启动画面的小型活动,避免白色的第一个屏幕停留太久。然后这个启动重定向我的主要活动。

这在我的情况下也很有用,因为我可以在启动画面期间启动一些连接过程。您可以按照以下示例操作:http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/

相关问题