为什么我的应用程序的UI没有在VS android app模拟器上显示(API级别19和23)?

问题描述 投票:0回答:1

我的应用程序确实显示在模拟器中,但当我点击它时,VS模拟器只显示我的应用程序的空白屏幕。 enter image description here

下面是我的FirstLogin活动的代码

package com.example.android.fantappstic_app;

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

public class FirstLogin extends AppCompatActivity {

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

        Button login_button = (Button) findViewById(R.id.login_button);
        final EditText user_field = (EditText)findViewById(R.id.user_field);
        final EditText pass_field = (EditText)findViewById(R.id.pass_field);
        Button signup_button = (Button) findViewById(R.id.signup_button);

        login_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(user_field.getText().toString().equals("codergal") && pass_field.getText().toString().equals("12345"))
                {
                    Intent GotoHomeScreen = new Intent(FirstLogin.this, HomeScreen.class);
                    FirstLogin.this.startActivity(GotoHomeScreen);
            }

                else
                {
                    Toast.makeText(getApplicationContext(), "Wrong Credentials",Toast.LENGTH_SHORT).show();

        }

    }
});
        signup_button.setOnClickListener(new View.OnClickListener() {
            @Override

            public void onClick(View v) {
                Intent GotoSignUpBasic = new Intent(FirstLogin.this, SignUpBasicInfo.class);
                FirstLogin.this.startActivity(GotoSignUpBasic);
            }
        });
    }}

下面是我的FirstLogin活动的XML文件:

`<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.fantappstic_app.HomeScreen">

    <TextView
        android:id="@+id/login_welcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome to App!"
        android:textSize="36sp"
        tools:layout_editor_absoluteY="47dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <EditText
        android:id="@+id/user_field"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Username"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        tools:layout_editor_absoluteY="258dp" />

    <EditText
        android:id="@+id/pass_field"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword"
        android:text="Password"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        tools:layout_editor_absoluteY="325dp" />

    <Button  
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="74dp"
        android:onClick="login"
        android:text="Log In"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <Button
        android:id="@+id/signup_button"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="148dp"
        android:text="Sign Up"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="16dp" />
</android.support.constraint.ConstraintLayout>

最后,这是我的AndroidManifest.xml文件。我添加了FirstLogin作为HomeScreen活动的父功能。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.fantappstic_app">

    <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=".HomeScreen"
            android:parentActivityName=".FirstLogin">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

    </application>

</manifest>

基本上,a)我在任何地方都没有出现任何错误b)我设计了按钮和TextView等组件,但它们没有出现在VS Emulator中。此外,我的VS Emulator是5.7“Marshmallow(6.0.0)XHDPI Phone API Level 23.我还尝试了5”KitKat(4.4)XXHDPI Phone API Level 19作为不同的设备。

javascript android android-studio android-emulator visual-studio-emulator
1个回答
0
投票

这是正确的代码。

    <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.example.android.fantappstic_app">

            <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=".FirstLogin"
                  >
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />

                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
                </activity>
<activity android:name=".HomeScreen"
            android:parentActivityName=".FirstLogin" />
                <activity android:name=".SignUpBasicInfo"></activity>

            </application>

        </manifest>
© www.soinside.com 2019 - 2024. All rights reserved.