代码之家  ›  专栏  ›  技术社区  ›  Green Yoshi

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

  •  0
  • Green Yoshi  · 技术社区  · 8 年前

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

    下面是我的首次登录活动的代码

    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作为主屏幕活动的父功能。

    <?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)我设计了按钮和文本视图等组件,但它们没有显示在VS Emulator中。此外,我的VS Emulator是一款5.7英寸Marshmallow(6.0.0)XHDPI手机API Level 23。我还尝试将5英寸KitKat(4.4)XXHDPI手机API Level 19作为一款不同的设备。

    1 回复  |  直到 8 年前
        1
  •  0
  •   InziKhan    8 年前

    这是正确的代码。

        <?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>