[英]Title bar keeps appearing, even with requestWindowFeature or android:theme
我的問題就是自定義標題欄 - 系統標題欄短暫顯示的問題?
但我無法達到和@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();
}
}
感謝您的幫助!
放:
android:theme="@android:style/Theme.NoTitleBar"
在您的應用程序選項卡下,而不是您的活動
在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"
一個簡單的方法刪除或你的布局樣式標簽,並在你的Manifest活動標簽下添加android:theme="@android:style/Theme.NoTitleBar"
使用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>
結果如下:
在您的MainActivity中使用此功能
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
基於Krunal解決方案,您只需將此行放在activity.xml文件的<activity>
標記內:
android:theme="@style/Theme.AppCompat.NoActionBar"
IE取代: 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添加任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.