所以我试图为我试图制作的这个Android应用程序实现启动画面。但是,在查看了大量的堆栈溢出解决方案之后,它们似乎都没有解决它。
有几个问题:
当初始屏幕转换到主屏幕时,主屏幕只有白色的操作栏,没有" Hello World!"。
闪屏本身非常黑。不是黑色,但要么不显示图片,要么显示它的前25%。我使用的启动画面位于:http://www.onlymobilepro.com/2013/01/16/android-beginner-creating-splash-screen/(这仅用于测试目的)
所以这是两个最大的问题。启动画面在正确的时间过渡,但发生了这些奇怪的故障。这是我的代码。
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
fragment_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.studyapp.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
SplashActivity.java
public class SplashActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashActivity.this, MainActivity.class);
SplashActivity.this.startActivity(i);
SplashActivity.this.finish();
}
}, 3000);
}
fragment_splash.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:id="@+id/splashscreen"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:src="@drawable/splash"/>
</LinearLayout>
最后,Manifest。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.studyapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19"
android:screenOrientation="portrait"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.example.studyapp.MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.example.studyapp.SplashActivity"
android:label="@string/title_activity_splash"
android:theme="@style/Theme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
感谢您的帮助!我已经被困在这个问题上几个小时了。