简体   繁体   English

如何在Android Studio中查看“ Hello World!” TextView?

[英]How can I view “Hello World!” TextView in Android Studio?

I have just started learning development on Android, and I am not able to view "Hellow World!" 我刚刚开始学习Android上的开发,但无法查看“ Hellow World!”。 TextView in the Design Tab. 在设计选项卡中的TextView。

MainActivity.java: MainActivity.java:

package com.dummy.demoapp;

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

public class MainActivity extends AppCompatActivity {

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

activity_main.xml: activity_main.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=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

AndroidManifest.xml: AndroidManifest.xml:

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

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

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

</manifest>

The TextView appears in the Component Tree, but the preview of the activity is totally blank: TextView出现在“组件树”中,但活动的预览完全空白:

在此处输入图片说明

I tried zooming in, but the TextView is just not there. 我尝试放大,但TextView不存在。

[EDIT]: The red exclamation (!) gives me the following message: [编辑]:红色惊叹号(!)给我以下消息:

在此处输入图片说明

And refreshing doesn't solve the problem. 刷新并不能解决问题。 Any help? 有什么帮助吗?

有时,Android Studio可能无法成功构建,构建-> Build&Run,然后如果可以打个招呼就可以选择虚拟设备,这与您的IDE无关,不是您的代码问题。

我认为这是您默认的AppTheme颜色为白色,尝试为TextView添加颜色

android:textColor="@android:color/black"

Go to style.xml and change this: 转到style.xml并更改它:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Click on the blue icon at the top left corner and then click on force layout. 单击左上角的蓝色图标,然后单击强制布局。 and You will see the Hello World! 您将看到Hello World!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM