fiverr freelancer
fiverr freelancer

Reputation: 165

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.

Upvotes: 8

Views: 12894

Answers (6)

Muhammad Rizwan
Muhammad Rizwan

Reputation: 37

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

Upvotes: -2

Arun Krishna
Arun Krishna

Reputation: 101

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

Upvotes: 10

tgrable
tgrable

Reputation: 1061

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

Upvotes: 5

Quick learner
Quick learner

Reputation: 11477

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>

Upvotes: 0

Mohammad Rbabah
Mohammad Rbabah

Reputation: 456

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>

Upvotes: 1

Joaqu&#237;n
Joaqu&#237;n

Reputation: 1136

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>

Upvotes: 0

Related Questions