[英]How can I view “Hello World!” TextView in Android Studio?
我剛剛開始學習Android上的開發,但無法查看“ Hellow World!”。 在設計選項卡中的TextView。
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:
<?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:
<?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>
TextView出現在“組件樹”中,但活動的預覽完全空白:
我嘗試放大,但TextView不存在。
[編輯]:紅色驚嘆號(!)給我以下消息:
刷新並不能解決問題。 有什么幫助嗎?
有時,Android Studio可能無法成功構建,構建-> Build&Run,然后如果可以打個招呼就可以選擇虛擬設備,這與您的IDE無關,不是您的代碼問題。
我認為這是您默認的AppTheme顏色為白色,嘗試為TextView添加顏色
android:textColor="@android:color/black"
轉到style.xml
並更改它:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
至
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
單擊左上角的藍色圖標,然后單擊強制布局。 您將看到Hello World!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.