Android Studio:新活动以空白屏幕打开 [英] Android Studio: New activity opens as blank screen

查看:34
本文介绍了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的Activity布局

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:新活动以空白屏幕打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆