Android启动屏幕没有';t显示

Android启动屏幕没有';t显示,android,android-layout,splash-screen,Android,Android Layout,Splash Screen,我定义了以下启动屏幕(splash.xml): 这是布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout

我定义了以下启动屏幕(splash.xml):

这是布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/Banner2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView1" />

    <Button
        android:text="Ok"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button_ok" />


</LinearLayout>

布局没有太多,但我得到的错误是:

`无法实例化活动组件信息{MyAndroid.MyAndroid/MyAndroid.MyAndroid.activities.activity_main}:``

*更新*


已更新清单代码。

层列表
在活动xml中不是有效的容器。请替换为任何布局容器,如LinearLayout、RelativeLayout,它应该可以工作

其次,活动标记应该位于menifest文件中的应用程序标记内,如下所示-

示例-

<application>
  <activity></activity>
</application>

您的代码应该如下所示-

<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/AppTheme">
  <activity android:name=".activities.MainActivity"
    android:theme="@style/SplashTheme">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
</application>
</manifest>

层列表
不是活动xml中的有效容器。请替换为任何布局容器,如LinearLayout、RelativeLayout,它应该可以工作

其次,活动标记应该位于menifest文件中的应用程序标记内,如下所示-

示例-

<application>
  <activity></activity>
</application>

您的代码应该如下所示-

<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/AppTheme">
  <activity android:name=".activities.MainActivity"
    android:theme="@style/SplashTheme">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
</application>
</manifest>

我想你在这里有误解

您在SplashTheme中使用的“android:windowBackground”实际上不是android启动屏幕。它只是一个窗口,在您启动应用程序后会立即显示。此窗口将一直显示,直到应用程序的主要活动启动

通常,您可以在第一次启动应用程序时看到此windowBackground(冷启动)。但如果在冷启动后继续或热启动应用程序,则可能看不到windowBackground

有关更多详细信息,请参阅下面的链接


我想你在这里有误解

您在SplashTheme中使用的“android:windowBackground”实际上不是android启动屏幕。它只是一个窗口,在您启动应用程序后会立即显示。此窗口将一直显示,直到应用程序的主要活动启动

通常,您可以在第一次启动应用程序时看到此windowBackground(冷启动)。但如果在冷启动后继续或热启动应用程序,则可能看不到windowBackground

有关更多详细信息,请参阅下面的链接


没有错误,与
图层列表的结果完全相同,没有任何问题。哦,我收到了你的问题。你已将活动放置在应用程序标记之外,它应该在应用程序内部。我已更新了答案。请检查确定,将代码放置在应用程序标记内,应用程序崩溃,说它找不到
MainActivity
,这是因为我的布局名为
activity\u main
,更改了清单中的代码,应用程序再次崩溃。我将
LinearLayout
代码替换为原始的
图层列表
代码,得到了启动屏幕,但应用程序崩溃了。没有错误消息,只有一条
未处理的异常
消息。但是取得了进展。@PRESCOTCHARTIER您可以与我共享您的活动类代码吗?请在您的活动xml文件中添加一个id为Button_ok的按钮。没有错误,结果与
层列表
完全相同,没什么。哦,我知道你的问题了。你把活动放在应用程序标签外,它应该在应用程序内。我已经更新了答案。请检查OK,把代码放在应用程序标签内,应用程序崩溃了,说它找不到
MainActivity
,这是因为我的布局被称为
Activity\u main
,更改了清单中的代码,应用程序再次崩溃。我将
LinearLayout
代码替换为原始的
图层列表
代码,得到了启动屏幕,但应用程序崩溃了。没有错误消息,只有一条
未处理的异常
消息。但是取得了进展。@PrescottChartier您可以与我共享您的活动类代码吗?请在您的活动xml文件中添加一个id为Button_ok的按钮。我理解热启动和冷启动的区别。这不是我的问题,我的问题是启动屏幕根本不显示。我理解热启动和冷启动的区别。这不是我的问题,我的问题是启动屏幕根本不显示;此对话已结束。评论不用于扩展讨论;这段对话已经结束。
<application>
  <activity></activity>
</application>
<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/AppTheme">
  <activity android:name=".activities.MainActivity"
    android:theme="@style/SplashTheme">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
</application>
</manifest>