新活动以空白屏幕打开

新活动以空白屏幕打开

本文介绍了Android Studio:新活动以空白屏幕打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!
我只是从Android Studio开始.我搜索了一个匹配的问题,但没有高兴,如果您已经看过这个问题,请大喊大叫!

Hello!
I'm just starting in Android Studio. I searched for a matching question but no joy, please yell out if you've seen this one already!

我的主要活动有一个按钮可以打开第二个活动,该按钮可以工作并打开.但是第二个活动显示为空白屏幕,而不是应该显示的文本.

My main activity has a single button which opens the second activity, the button works and it opens. But the second activity shows as a blank screen instead of the text that should be there.

为任何不相关的复制/粘贴致歉!

Apologies for any irrelevant copy/paste!

清单:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.NoActionBar" >
        <activity
            android:name=".MainActivity"
            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=".fiveThreeOne"
            android:label="@string/title531">
        </activity>
    </application>

主要活动:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:textColor="#ffdedede"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="fiveThreeOne"
        android:textAllCaps="false"
        android:id="@+id/open531btn"
        android:layout_below="@+id/mainTitle"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="38dp" />

</RelativeLayout>

主类中的按钮代码

public class MainActivity extends ActionBarActivity {

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

        Button open531button = (Button) findViewById(R.id.open531btn);
        open531button.setOnClickListener(new OnClickListener(){

            public void onClick(View v){
                startActivity(new Intent(MainActivity.this, fiveThreeOne.class));
            }
        });

    }

第二个活动xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:text="@string/title531"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:editable="false"
        android:textSize="35sp"
        android:id="@+id/title531"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />


</RelativeLayout>

谢谢!

推荐答案

您是否在setContentView()行中设置了活动的布局,如下所示.这是activity_second是我的SecondActivity的活动布局

Have you set the layout for your activity in the line setContentView() like this. Here activity_second is the activity layout of my SecondActivity

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

如果不是,那么您的活动将显示为空白.希望这能解决您的问题.

if not then your activity will show up as blank.Hope this solves your problem.

这篇关于Android Studio:新活动以空白屏幕打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:33