Luc*_*ota 6 android splash-screen titlebar custom-titlebar
我的问题就是自定义标题栏 - 系统标题栏短暂显示的问题?
但我无法达到和@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>
Run Code Online (Sandbox Code Playgroud)
布局:
<?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>
Run Code Online (Sandbox Code Playgroud)
样式:
<style name="SplashTheme" parent="@android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:background">@drawable/splash</item>
</style>
Run Code Online (Sandbox Code Playgroud)
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();
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮忙!
放:
android:theme="@android:style/Theme.NoTitleBar"
Run Code Online (Sandbox Code Playgroud)
在您的应用程序选项卡下,而不是您的活动
在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);
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
第一个主题将显示状态栏,如果你想要隐藏这个也使用第二个主题.我也使用属性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>
Run Code Online (Sandbox Code Playgroud)
在您的清单中使用此
<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>
Run Code Online (Sandbox Code Playgroud)
如果您想在清单中使用第二个主题更改
android:theme="@style/SplashTheme" 同 android:theme="@style/SplashTheme.FullScreen"
一种简单的方法是在布局中删除或设置标记样式,并android:theme="@android:style/Theme.NoTitleBar"在活动标记下添加Manifest
| 归档时间: |
|
| 查看次数: |
13800 次 |
| 最近记录: |