Android Studio新活动布局黑屏

时间:2017-06-20 02:02:35

标签: android android-studio android-activity android-layout

我正在为我的学校项目编码/尝试编码。我在创建第二个活动时遇到了麻烦。

使用Android Developer网站上的练习文件一切正常。 但是在我的主项目文件中,每当我打开新创建的空活动的XML文件时(这里:DayView),它都是黑屏。我忽略了它并尝试运行应用程序但是在调用第二个活动时它不起作用。

如果有人可以帮助我,我会很高兴。由于我是新手,所以让我知道下次写这篇帖子时我需要做些什么。

enter image description here

清单:

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

    <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="@android:style/Theme.Holo.NoActionBar.Fullscreen">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="sensorLandscape"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>`

MainActivity

package com.classagenda.ca.classagenda;

    import android.content.Intent;
    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.View;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.EditText;
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;

    public class MainActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
         //   Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
           // setSupportActionBar(toolbar);
        }

        /** Called when the user taps the Send button */
        public void Montag(View view) {
            Intent intent = new Intent(MainActivity.this, DayView.class);
           // EditText editText = (EditText) findViewById(R.id.editText);
           // String message = editText.getText().toString();
           // intent.putExtra(EXTRA_MESSAGE, message);
            startActivity(intent);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu_main, menu);
            return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();

            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }

            return super.onOptionsItemSelected(item);
        }
    }`

DayView Second Activity:

 package com.classagenda.ca.classagenda;

    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;

    public class DayView extends AppCompatActivity {

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

        }
    }

layout activity_day_view.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.classagenda.ca.classagenda.DayView"
>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="DayView"
        android:textSize="30sp"
        tools:layout_editor_absoluteX="214dp"
        tools:layout_editor_absoluteY="106dp" />
</android.support.constraint.ConstraintLayout>

0 个答案:

没有答案