繁体   English   中英

启动画面问题(启动画面无图像,首页无文字)

[英]Splash Screen Issue (No image on splash, no text on home)

因此,我尝试为我要制作的这个Android应用程序实现启动屏幕。 但是,在查看了很多堆栈溢出解决方案之后,似乎都没有一个解决方案。

有几个问题:

  1. 当初始屏幕过渡到主屏幕时,主屏幕只是带有操作栏的白色,而没有“ Hello World!”。

  2. 初始屏幕本身很黑。 不会变黑,但是要么不显示图片,要么显示前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>

最后是清单。

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

谢谢你的帮助! 我已经在这个问题上停留了几个小时。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM