2012-06-26 28 views
5

Câu hỏi của tôi là chính xác Sabe như Custom titlebar - system titlebar being shown for a brief moment?Tiêu đề thanh tiếp tục xuất hiện, ngay cả với requestWindowFeature hoặc android: theme

Nhưng tôi không thể đạt được kết quả tương tự như @Jerry đã viết về câu trả lời tốt nhất. "Khi tôi chuyển sang sử dụng một chủ đề để nói với khuôn khổ Tôi không muốn có một tiêu đề, vấn đề đi đi và bây giờ tôi thấy tiêu đề của riêng tôi trực tiếp trên nạp đầu tiên"

Mã của tôi:

Manifest:

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

bố trí:

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

Kiểu:

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

Cảm ơn bạn đã giúp đỡ!

Trả lời

6

Đặt:

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

Dưới tab ứng dụng của bạn, không hoạt động của bạn một

+1

đẹp và đơn giản! –

+0

Nó rất đơn giản để chỉ tác giả mới có thể hiểu chính mình! – Sayonara

9

Sử dụng chủ đề của bạn trong hoạt động của bạn trên AndroidManifest không Layout của bạn !!

này sẽ làm việc: 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> 

chủ đề đầu tiên sẽ hiển thị trên thanh trạng thái cho bạn nếu bạn muốn ẩn cái này cũng dùng thứ hai theme.Also tôi đã sử dụng thuộc tính windowBackround để null bởi vì bạn sẽ sử dụng hình ảnh của bạn như một backround cho RootLayout của bạn sau đó, vì vậy tốt hơn là không ghi đè lên màu nền được sử dụng bởi chủ đề android mặc định cho vấn đề hiệu suất.

trong splashscreen_layout của bạn, bạn có thể sử dụng

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

Trong sử dụng biểu hiện của bạn này

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

nếu bạn muốn sử dụng sự thay đổi chủ đề thứ hai trong biểu hiện của bạn

android:theme="@style/SplashTheme" với android:theme="@style/SplashTheme.FullScreen"

Một cách đơn giản loại bỏ hoặc bạn phong cách thẻ trong cách bố trí của bạn và thêm android:theme="@android:style/Theme.NoTitleBar" trong Manifest của bạn dưới hoạt động của thẻ

+0

Cảm ơn bạn! Miễn là tôi không muốn một tiêu đề tùy chỉnh, câu trả lời của @ Cruceo làm việc tốt. Nhưng máy của bạn rất hoàn chỉnh và được giải thích tốt, và có thể giúp những người muốn có tiêu đề tùy chỉnh. –

0

Trong sử dụng MainActivity bạn này

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

Với AppCompat này dường như hoạt động khác nhau.

giải pháp sau làm việc cho tôi:

Thêm phong cách chủ đề mới không có thanh hành động trong styles.xml của bạn và thiết lập 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> 


Bây giờ thực hiện phong cách cùng một chủ đề để hoạt động màn hình của bạn trong 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> 

Dưới đây là kết quả:

enter image description here

Các vấn đề liên quan