I am trying to build my first Android app using Android Studio and Firebase. I have it all connected and it is showing the content from the database and images from the firebase storage just fine. The problem is, for some reason my text isn’t showing up that I added into the xml. At the bottom of the post there are 3 buttons, “like”, “comment”, and “re-post” they have an icon, then text next to them. The icons are showing up perfectly, but the text will not show up. Here is the “include_post_actions.xml” where the problem lies…
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_below="@+id/post_action_layout" android:layout_above="@+id/include" android:layout_width="match_parent" android:layout_height="75dp" android:layout_weight="1" android:gravity="center_vertical"> <LinearLayout android:id="@+id/post_action_buttons" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> <com.like.LikeButton app:icon_type="heart" app:icon_size="18dp" android:id="@+id/star_button" android:layout_width="18dp" android:layout_height="18dp" /> <TextView android:id="@+id/post_likes_count" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:textColor="@color/colorBlack" android:maxLines="1" tools:text="Like" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <ImageView android:id="@+id/post_comment_icon" android:layout_width="20dp" android:layout_height="20dp" android:src="@drawable/ic_question_answer_black_24dp" /> <TextView android:id="@+id/post_comments_count" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:textColor="@color/colorBlack" android:maxLines="1" tools:text="Comment" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <ImageView android:id="@+id/post_repost_icon" android:layout_width="20dp" android:layout_height="20dp" android:src="@drawable/ic_autorenew_black_24dp" /> <TextView android:id="@+id/post_repost_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:textColor="@color/colorBlack" android:maxLines="1" tools:text="Repost" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/post_action_buttons"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginStart="20dp" android:gravity="center_vertical" tools:text="Likes Count" android:id="@+id/like_count_text" android:maxLines="1" /> </LinearLayout> </RelativeLayout>
In the preview the text shows up right next to the icons, but when I run it on an emulator only the icons are there, and I can’t figure out why. Please help. Thank you. The preview in Android Studio
Advertisement
Answer
The issue is that you are using tools:text="Repost"
. That only displays in the preview mode, you need to use android:text="Repost"
to actually display it.
The tools
namespace is for editor purposes only and is a great way to align things without actually setting values. If you want to actually display the text, however, you need to use the android
namespace.