我的问题就是Custom titlebar - system titlebar being shown for a brief moment?
但我无法达到和@Jerry在最佳答案上所写的相同的结果。 "当我切换到使用主题告诉框架我不想要一个标题时,问题消失了,我现在直接在第一次加载时看到我自己的标题"
我的代码:
清单:
<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="3" android:versionName="1.0.2"
package="androidhive.dashboard" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:icon="@drawable/icone" android:label="@string/app_name">
<activity
android:name="com.androidhive.dashboard.SplashScreen"
android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/SplashTheme"
>
<ImageView
android:id="@+id/splashscreen_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:contentDescription="Splash"
android:scaleType="centerCrop"
android:src="@drawable/splash"
style="@style/SplashTheme" />
</LinearLayout>
风格:
<style name="SplashTheme" parent="@android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:background">@drawable/splash</item>
</style>
SplashScreen.java
public class SplashScreen extends Activity implements Runnable{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(R.style.SplashTheme);
setContentView(R.layout.splashscreen_layout);
Handler h = new Handler();
h.postDelayed(this, 15000);
}
@Override
public void run() {
startActivity(new Intent(this, AndroidDashboardDesignActivity.class));
finish();
}
}
感谢您的帮助!
答案 0 :(得分:9)
把:
android:theme="@android:style/Theme.NoTitleBar"
在您的应用程序标签下,而不是您的活动
答案 1 :(得分:9)
在AndroidManifest中的活动中使用您的主题,而不是在您的布局中使用
这将有效: SplashScreen.java
public class SplashScreen extends Activity{
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
final Runnable runnable = new Runnable() {
@Override
public void run() {
Intent intent=new Intent(SplashScreen.this, AndroidDashboardDesignActivity.class);
startActivity(intent);
finish();
}
};
handler = new Handler();
handler.postDelayed(runnable, 5000);
}
theme.xml
<style name="SplashTheme" parent="android:Theme">
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="SplashTheme.FullScreen" parent="android:Theme">
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
第一个主题将显示状态栏,如果你想隐藏这个也使用第二个主题。我也使用属性windowBackround为null因为你将使用你的图像作为你的RootLayout的背景,之后,因此,最好不要覆盖默认android主题用于性能问题的背景颜色。
在你的splashscreen_layout中你可以使用这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash"
android:orientation="vertical" >
</RelativeLayout>
在你的清单中使用这个
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/icone"
android:label="@string/app_name" >
<activity
android:name="com.androidhive.dashboard.SplashScreen"
android:label="@string/app_name"
android:theme="@style/SplashTheme"
android:windowSoftInputMode="stateHidden|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如果您想在清单中使用第二个主题更改
带有android:theme="@style/SplashTheme"
的 android:theme="@style/SplashTheme.FullScreen"
一种简单的方法是删除布局中的标记,并在活动标记下的清单中添加android:theme="@android:style/Theme.NoTitleBar"
答案 2 :(得分:2)
使用AppCompat
,这似乎有所不同。
以下解决方案为我工作:
在styles.xml
添加没有操作栏的新主题样式并设置parent="Theme.AppCompat.NoActionBar"
。
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorPrimary</item>
</style>
现在为androidManifest.xml
<activity
android:name=".ActivityName"
android:theme="@style/SplashTheme"> // apply splash them here
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
结果如下:
答案 3 :(得分:0)
在您的MainActivity中使用此
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
答案 4 :(得分:0)
基于Krunal解决方案,您可以简单地将此行放在activity.xml文件的<activity>
标记内:
android:theme="@style/Theme.AppCompat.NoActionBar"
I.E。
更换:
android:theme="@style/SplashTheme"
具有:
android:theme="@style/Theme.AppCompat.NoActionBar"
内部
<activity
android:name=".ActivityName"
android:theme="@style/SplashTheme"> // replace this line
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
给予:
<activity
android:name=".ActivityName"
android:theme="@style/Theme.AppCompat.NoActionBar"> // line replaced
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这可以避免您在styles.xml中添加任何内容。