TextView is Not Showing any Text

Viewed 10389

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.

6 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

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" />

you are using ConstraintLayout and it needs special properties to be provided to see all views. since you are a beginner as you say I recommend to start with linear layouts. replace your code with this one.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">
 <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        />

    <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" />
</LinearLayout>

you need to constraint your widgets if you gonna use constraint layout. First try with a linearlayout, it will be more simple if you just want to display a textview with a hello world

    <LinearLayout


        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#134A80">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"          
            android:text="Hello World"
            android:textStyle="bold"
            android:textColor="#FFF"
            android:layout_marginTop="8dp"/>
      </LinearLayout>

Try this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:text="TextView"
        android:alignParentBottom="true"
        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" />

</RelativeLayout>

user android:text="hello world!" instead of tool:text="hello world"

Related