2012-06-26 12 views
5

Moje pytanie jest dokładnie sabe jak Custom titlebar - system titlebar being shown for a brief moment?Tytuł bar ciągle pojawiające się nawet z requestWindowFeature lub Android: motyw

Ale nie mogłem osiągnąć takie same wyniki jak @Jerry napisał na najlepszą odpowiedź. „Kiedy przeszedłem do korzystania z tematem powiedzieć ram nie ma tytuł, problem odszedł i teraz widzę mój własny tytuł bezpośrednio przy pierwszym obciążeniu”

Mój kod:

Oczywisty:

<?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> 

układ:

<?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> 

Styl:

<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(); 
} 
} 

Dziękujemy za pomoc!

Odpowiedz

6

Put:

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

na karcie zgłoszenia, a nie swoją działalność jeden

+1

ładne i proste! –

+0

To takie proste, więc tylko autor może zrozumieć samego siebie! – Sayonara

9

Użyj motywu w swojej działalności na AndroidManifest nie w układzie !!

to będzie działać: 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> 

pierwszy motyw pojawi się pasek stanu dla Ciebie, jeśli chcesz ukryć ten również użyć drugi temat. Również użyłem atrybutu windowBackround do wartości null, ponieważ użyjesz swojego obrazu jako backround dla RootLayout po tym, więc lepiej nie przesłonić koloru tła używanego przez domyślny motyw dla Androida pod względem wydajności.

w splashscreen_layout można użyć tej

<?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> 

W swojej oczywistego zastosowania tego

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

jeśli chcesz korzystać z drugą zmianę temat w oczywisty

android:theme="@style/SplashTheme" z android:theme="@style/SplashTheme.FullScreen"

prosty sposób usunąć lub styl tag w układzie i dodać android:theme="@android:style/Theme.NoTitleBar" w Manifest ramach działalności tagu

+0

Dziękujemy! Tak długo, jak nie chciałem niestandardowego tytułu, odpowiedź @ Cruceo działała dobrze. Ale twoje jest bardzo kompletne i dobrze wyjaśnione, i może pomóc tym, którzy chcą niestandardowych tytułów. –

0

W użytku główną działalność ta

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

Z AppCompat wydaje działa inaczej.

następujące rozwiązanie pracował dla mnie:

Dodaj nowy styl rozrywki bez paska akcji w styles.xml i ustawić 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> 


teraz wdrożyć ten sam styl motyw do aktywności ekran powitalny w 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> 

Oto wynik:

enter image description here