Android 如何解决kotlin应用程序的这个空白屏幕问题?
因此,当我编译启动屏幕的代码并运行它时,它只显示一个空白屏幕。布局编辑器完美地呈现了屏幕。我最近换了Kotlin,所以我可能在代码中犯了一些错误Android 如何解决kotlin应用程序的这个空白屏幕问题?,android,kotlin,Android,Kotlin,因此,当我编译启动屏幕的代码并运行它时,它只显示一个空白屏幕。布局编辑器完美地呈现了屏幕。我最近换了Kotlin,所以我可能在代码中犯了一些错误 package com.superstar.scrolls2 import android.content.Intent import android.os.Bundle import android.os.Handler import android.os.PersistableBundle import androidx.appcompat.ap
package com.superstar.scrolls2
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
class LauncherActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
setContentView(R.layout.launcher_layout)
Handler().postDelayed({
var i : Intent=Intent(this@LauncherActivity, LoginActivity::class.java)
startActivity(i)
}, 5000)
}
}
显示
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.superstar.scrolls2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Scrolls2" >
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
<activity android:name=".LauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".LoginActivity"/>
</application>
</manifest>
布局呢
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@drawable/parchment_chinese"
android:id="@+id/linearLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="124dp"
android:background="#00FFFFFF"
android:src="@drawable/scroll_one_coloured"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499"
tools:layout_conversion_absoluteHeight="124dp"
tools:layout_conversion_absoluteWidth="163dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="144dp"
android:fontFamily="@font/medievalsharp"
android:text="Scrolls"
android:textColor="#9A5712"
android:textSize="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.511"
app:layout_constraintStart_toStartOf="parent"
tools:layout_conversion_absoluteHeight="59dp"
tools:layout_conversion_absoluteWidth="157dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
因此,启动屏幕是完全黑色的,顶部的工具栏显示应用程序名称。为了测试,我用java编写了相同的屏幕,效果很好。应用程序没有崩溃或其他任何问题。仅出于测试目的,我没有完成()launcher活动以了解它是否真正启动LoginActivity,但事实并非如此,因为堆栈中只有一个活动。问题是您覆盖了错误的
onCreate()
,它将永远不会被调用,您的内容也不会被设置
使用
而不是
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?)
问题是您正在重写错误的
onCreate()
,它将永远不会被调用,您的内容也不会被设置
使用
而不是
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?)
哦,是的,你是对的,该死的。非常感谢你。我以为这是为kotlin Sign创建的onCreate--
我以为这是为kotlin Sign创建的onCreate-
覆盖不会因为您使用的是另一种语言而更改很高兴我能提供帮助,如果您认为答案回答了您的问题,请接受答案。哦,是的,该死的,您是对的。非常感谢你。我以为这是为kotlin Sign创建的onCreate--我以为这是为kotlin Sign创建的onCreate-
覆盖不会更改,因为您使用的是不同的语言很高兴我能提供帮助,如果您认为答案回答了您的问题,请接受答案。