Home>

Thanks for your help.
I'm using Android Studio, but I'm sorry for the rudimentary things.
I placed a textview in the created project, assigned an id in MainActivity and set the character, but the character does not appear in the xml preview.
However, if you build it normally, it will be displayed correctly in the emulator.
[Attached photo: Preview on the left, emulator on the right, "Test display" in the middle does not appear in the preview]

This is the first time I've used it so far, and I'm having a hard time thinking about the target method.
[You may have made a mistake in some operation. .. .. .. ]
I had a similar question, so I thought I'd try it.
I don't know how to fix it. .. .. ..
I'm sorry, but if you know how to deal with it, please teach me.

--MainActivity.java--
package com.e.tonikakukawaii;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_main);
        TextView textView = findViewById (R.id.scandialog);
        textView.setText ("test display");
    }
}
--activity_main.xml--
<? xml version = "1.0" encoding = "utf-8"?>

  <Button
        android: id = "@ + id/button"
        android: layout_width = "150dp"
        android: layout_height = "64dp"
        android: text = "Button"
        tools: layout_editor_absoluteX = "237dp"
        tools: layout_editor_absoluteY = "462dp" />

  <TextView
        android: id = "@ + id/textView2"
        android: layout_width = "170dp"
        android: layout_height = "61dp"
        android: background = "# FFFFFF"
        android: text = "TextView"
        app: layout_constraintEnd_toEndOf = "parent"
        app: layout_constraintStart_toStartOf = "parent"
        tools: layout_editor_absoluteY = "46dp" />
  <TextView
        android: id = "@ + id/scandialog"
        android: layout_width = "177dp"
        android: layout_height = "26dp"
        android: textColor = "# 000000"
        app: layout_constraintBottom_toBottomOf = "parent"
        app: layout_constraintEnd_toEndOf = "parent"
        app: layout_constraintStart_toStartOf = "parent"
        app: layout_constraintTop_toTopOf = "parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
--build.gradle (: app)-
apply plugin:'com.android.application'
android {
    compileSdkVersion 30
    buildToolsVersion "30.0.1"
    defaultConfig {
        applicationId "com.e.tonikakukawaii"
        minSdkVersion 26
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile ('proguard-android-optimize.txt'),'proguard-rules.pro'
        }
    }
}
dependencies {
    implementation fileTree (dir: "libs", include: ["*. Jar"])
    implementation'androidx.appcompat: appcompat: 1.2.0'
    implementation'androidx.constraintlayout: constraintlayout: 2.0.2'
    testImplementation'junit: junit: 4.12'
    androidTestImplementation'androidx.test.ext: junit: 1.1.2'
    androidTestImplementation'androidx.test.espresso: espresso-core: 3.3.0'
}
  • Answer # 1

    The preview of xml is only the one described in xml.

    To explain the flow of the program roughly, the screen drawing process of the application reads xml in Java and adds the process later on the Java side.
    Therefore, the process set on the Java side is not reflected in the xml preview.
    If you only want to check the display, we recommend the following method.

    The value set by tools is not actually read and is displayed only when confirmed by xml preview.

    <TextView
            android: id = "@ + id/scandialog"
            android: layout_width = "177dp"
            android: layout_height = "26dp"
            android: textColor = "# 000000"
            app: layout_constraintBottom_toBottomOf = "parent"
            app: layout_constraintEnd_toEndOf = "parent"
            app: layout_constraintStart_toStartOf = "parent"
            app: layout_constraintTop_toTopOf = "parent"
            tools: text = "test display" />