2012-06-26 35 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