Android布局无法在设备中显示

Android布局无法在设备中显示,android,xml,layout,Android,Xml,Layout,我的Android Studio版本是1.5.1 我创建了一个XML,它可以在AndroidStudio中很好地显示出来, 但当我在genymotion或我的手机中运行它时,它无法显示布局 我对此很恼火,我不知道怎么了 希望有人能帮助我 代码: 喷溅活动 import android.content.Intent; import android.os.Bundle; import android.os.PersistableBundle; import android.support.v7.a

我的Android Studio版本是
1.5.1

我创建了一个
XML
,它可以在AndroidStudio中很好地显示出来, 但当我在
genymotion
或我的手机中运行它时,它无法显示布局

我对此很恼火,我不知道怎么了

希望有人能帮助我

代码:

喷溅活动

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class SplashActivity extends AppCompatActivity {

    private Button mEnterButton; 
    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.enter_button:
                    Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(intent);
                    break;
            }
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.activity_splash);
        mEnterButton = (Button) findViewById(R.id.enter_button);
        mEnterButton.setOnClickListener(mOnClickListener);

    }
}
主要活动

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.button_first).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,SplashActivity.class);
                startActivity(intent);
            }
        });
    }
}
avtivity_splash_布局

<?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"
    android:gravity="center"
    android:background="@color/splashBackground">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/splash_tv_text"
        android:textSize="28sp"
        android:id="@+id/text_splash"
        android:textColor="@color/white"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/splash_click_to_inter"
        android:id="@+id/enter_button"/>

</LinearLayout>

显示

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

    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.geekband.geekbandprojects">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" >

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

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

</manifest>

我认为您尚未将
Splash活动设置为启动
活动
。因此,在
清单上添加(或更改)以下代码:

<activity
           android:name=".Splash"
           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=".MainActivity"/>

并让我们知道您的
main活动
代码,当然还有您的
清单

之后我会更新我的答案


当然,我认为您应该在Oncreate方法上使用
onClick

为什么需要持久化捆绑包? 使您的onCreate方法类似于:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //anything here
}

我很讨厌
是的,你确实很讨厌。因为您将代码发布为图像,而不是文本。很抱歉,我必须发布2个类代码、2个xml代码、1个运行结果和1个xml预览。因此我认为pic可能更简单…对于未来,请记住粘贴代码,而不是图像。图像只是为了向我们展示你想要实现的目标和你得到的结果。但我不能拿出其中的一部分,纠正它,然后把它作为一个答案贴出来。太棒了。下一步,接受解决你问题的答案。好的。真的感谢@Andy the android、@TheGuy和你。感谢你的帮助。我已经上传了主要活动和清单。我将我的代码改为@Andy the android gived,现在它运行良好!在Oncreate方法上使用onClick是否意味着这一点?:setOnClickListener(newview.OnClickListener(){@Override……});没错,这就是为什么我说你应该在这里发布你的日志,至少,我说,
我认为你应该使用onClick on Oncreate方法。
让我们知道这个答案是否有用,接受它作为最佳答案。Goodluck当我在类上使用onClick或Oncreate方法时有什么区别?这是另一个问题,请使用
提问