2012-06-26 36 views
5

我的问题是完全萨韦作为Custom titlebar - system titlebar being shown for a brief moment?标题栏继续出现,即使有requestWindowFeature或Android:主题

但作为@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(); 
} 
} 

谢谢你的帮助!

回答

6

地说:

android:theme="@android:style/Theme.NoTitleBar" 

在你的应用程序标签,而不是你的活动一个

+1

简单好用的! –

+0

这是如此简单,所以只有作者可以理解自己! – Sayonara

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> 

第一个主题会显示您的状态栏,如果你要隐藏这一个也使用第二个theme.Also我已经使用属性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"

一个简单的方法删除或你的布局,你的风格标签,并在你的清单下活动标签

+0

谢谢!只要我不想要自定义标题,@Cruceo的答案就可以正常工作。但是你的作品非常完整并且很好解释,并且可以帮助那些想要自定义标题的人。 –

0

添加android:theme="@android:style/Theme.NoTitleBar"在您的MainActivity使用该

getSupportActionBar().hide(); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
0

随着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> 

下面是结果:

enter image description here