Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView is Not Showing any Text

I just Installed Android Studio and Created a Project in it but whenever i add a TextView in it is not showing anything Even the TextView Already Created by the Android Studio Is not Showing Activity.xml code is

<?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="wrap_content"
    tools:context=".MainActivity"
    tools:layout_editor_absoluteY="25dp">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        tools:layout_editor_absoluteX="67dp"
        tools:text="Hello World" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        tools:text="sdfsfsfsfs" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        tools:text="Hello World" />

</android.support.constraint.ConstraintLayout>

Any Help Would Be appreciated.

like image 205
fiverr freelancer Avatar asked Mar 05 '23 13:03

fiverr freelancer


2 Answers

Probably a late answer, but as long as it helps someone.

You are using the property tools:text for your last textview. The tools namespace is just for layout preview in android studio.

For the textview to display something in runtime, you must use the android namespace and android:text property like so:

<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World" />

Also, only the first textview is constrained. Try adding constraints to the remaining TVs.

And, in case your design window is not showing any text but a blank screen, you may have to change the Theme for Preview in the design window to match your app theme (Eg: Material theme, Light, AppTheme, etc.) The sixth button, which shows "Material Theme" right now

like image 181
Arun Krishna Avatar answered Mar 10 '23 11:03

Arun Krishna


Try that for your constraint layout.

<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="wrap_content"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="Hello World" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="Hello World!"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView2"
        tools:text="sdfsfsfsfs" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:text="Hello World"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView3"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp" />

</android.support.constraint.ConstraintLayout>

Also, id/textview will not render anything when the app is run because there is no android:text property. tools:text is just for the layout editor.

<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        tools:text="Hello World" />
like image 28
tgrable Avatar answered Mar 10 '23 11:03

tgrable