尝试了多种解决方案后,启动画面未出现在android中

时间:2019-01-31 06:09:01

标签: android android-activity

我对android还是很陌生,我正在尝试通过遵循网站上的教程来实现启动屏幕。

我做了所有写在这里的东西,但是当我运行我的应用程序时,初始屏幕没有出现。

我从StackOverflow的许多问题中获得了参考,但这似乎不起作用

Splash screen does not appear

下面是我的“ activity_splash”文件,位于“ res-> layout-> activity_splash.xml”

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/googleg_standard_color_18" >

<ImageView
    android:id="@+id/imgLogo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:src="@drawable/image_offline" />

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:textSize="12dp"
    android:textColor="#454545"
    android:gravity="center_horizontal"
    android:layout_alignParentBottom="true"
    android:text="www.androidhive.info" />

下面是我在MainActivity.java文件旁边的“ SplashScreen.java”文件

// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashScreen.this, MainActivity.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
}

*

*下面是我的“ AndroidManifest.xml”文件**

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.webkit.PermissionRequest" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:name="android.gold.webview.codecanyon.com.bakairy.WebViewApp"
    android:theme="@style/AppTheme">
    <activity
        android:name="android.gold.webview.codecanyon.com.bakairy.MainActivity"
        android:configChanges="orientation|screenSize">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter android:label="@string/deeplinking">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <!-- Accepts URIs that begin with "https://bakairy.boehub.com/link=” -->
            <data android:scheme="http"
                android:host="https://bakairy.boehub.com"
                android:pathPrefix="/link="
                />

        </intent-filter>


    </activity>
    <activity android:name=".SplashScreen" />

    <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
</application>

3 个答案:

答案 0 :(得分:3)

由于您将MainActivity作为manifest中的启动器活动,因此未显示您的启动屏幕

更改您的manifest代码:

<activity android:name=".SplashScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<activity android:name=".MainActivity" />

答案 1 :(得分:0)

  

bro首先要启动活动,您必须先使其启动,我正在修改您的代码,而改用它。替换您的清单代码进行启动活动。并从主要活动中删除意图过滤器

  <activity android:name=".SplashScreen" >

            

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

答案 2 :(得分:0)

您只需要在初始屏幕中设置意图过滤器。 像这样。

<activity android:name=".SplashScreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

MainActivity不需要删除它的意图过滤器。