gpt4 book ai didi

java - Android 启动画面

转载 作者:太空狗 更新时间:2023-10-29 23:03:13 24 4
gpt4 key购买 nike

My Package Explorer

这是我的包资源管理器中的内容,所以让我们从头开始并努力解决我认为它所在的问题..

MainActivity.java -

 package com.drg.idoser;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

现在是 SplashActivity.java

package com.drg.idoser;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class SplashActivity extends Activity {

private static String TAG = SplashActivity.class.getName();
private static long SLEEP_TIME = 5; // Sleep for some time

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar

setContentView(R.layout.splash);

// Start timer and launch main activity
IntentLauncher launcher = new IntentLauncher();
launcher.start();
}

private class IntentLauncher extends Thread {
@Override
/**
* Sleep for some time and than start new activity.
*/
public void run() {
try {
// Sleeping
Thread.sleep(SLEEP_TIME*1000);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}

// Start main activity
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
SplashActivity.this.startActivity(intent);
SplashActivity.this.finish();
}
}
}

activity_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=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

</RelativeLayout>

飞溅.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@drawable/splash_bg"
android:layout_height="match_parent"
android:orientation="vertical" >


</LinearLayout>

AndroidManafest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drg.idoser"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.drg.idoser.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>

现在我认为我的问题出在 AndroidManafest.xml 我不认为当我从我的应用程序启动我的应用程序时我在 AndroidManafest.xml 中设置了 splach 屏幕手机它跳转到 activity_main.xml 而不是 splash.xml 我是 android 应用程序的新手所以我似乎找不到我的问题但我需要我的启动画面显示 5 秒如果有人有 TeamViwer 并且愿意帮助我发布我的 session 信息,如果它会更快的话。

最佳答案

更改您的 <application>标记到以下。您没有声明 SplashActivity,而是将 MainActivity 设置为启动器 Activity。

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.drg.idoser.SplashActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.drg.idoser.MainActivity"
android:label="@string/app_name" />
</application>

关于java - Android 启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15452061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com