In my Android app, I try to add a TextView to add titles to some of my Activities. However, it doesn't seem to work, since in none of my activities the TextViews don't show up. I'm new to developing Android apps, so I may be doing something fundamentally wrong, but I tried out to add different elements (Buttons, Plain Text, ...) and they all show up, I only have the Problem with my Textview.
Here's my code:
<androidx.constraintlayout.widget.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=".WishlistActivity">
<TextView
android:id="@ id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="173dp"
android:layout_marginTop="87dp"
android:layout_marginEnd="156dp"
android:layout_marginBottom="625dp"
android:text="Wishlist stuff"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>```
CodePudding user response:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@ id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="173dp"
android:layout_marginTop="87dp"
android:layout_marginEnd="156dp"
android:layout_marginBottom="625dp"
android:text="Wishlist stuff"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
There is no error in code just correct the margin according to your screen size.
CodePudding user response:
Remove margins inside Textview and try it
CodePudding user response:
You probably just drag&dropped the textview into the ContraintLayout and moved it to a specific place. Android Studio moves the View by adjusting the margins accordingly. And then you set it to 0dp, hoping it would expand, which it normally would do. You just missed to remove or adjust the margins afterwards.
Try this:
<TextView
android:id="@ id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Wishlist stuff"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
CodePudding user response:
is the Textview doesn't show when you run the app or just in android studio render? also can you provide more info like App theme you are using in style.xml and the version of material-components in your dependencies sections.
things that may help you to solve it :
1 -try to update your material-components dependency
2- change the app theme in style.xml