Thudner
Thudner

Reputation: 1169

TextView not showing even I can see it on design and other views showing

I have RelativeLayout which contains images and texts. images are showing but text not showing even I can see them on design. I use bellow XML in include tag inside CoordinatorLayout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toptoolbarview"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/colorPrimary"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<View
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:layout_alignParentTop="true"
    android:background="@color/black" />
<ImageView
    android:id="@+id/sort"
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:layout_alignParentStart="true"
    android:layout_centerVertical="true"
    android:layout_marginStart="5dp"
    android:layout_marginLeft="25dp"
    android:contentDescription="@string/provider_not_found"
    android:src="@drawable/sort" />

<TextView
    android:id="@+id/sortTxt"
    android:layout_width="32dp"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="15dp"
    android:layout_toEndOf="@id/sort"
    android:textColor="#FFFFFF"
    android:textSize="18sp"
    android:textStyle="bold"
    tools:text="@string/sort" />
 </RelativeLayout>

Bellow where the above xml included:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
 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"
                                             android:fitsSystemWindows="true"
                                             tools:context="io.github.luizgrp.sectionedrecyclerviewadapter.demo.HomeActivity">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppBarOverlay">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/PopupOverlay"/>

<----- THIS where I include the XML contains the above code --- >

    <include
        layout="@layout/toptoolbar"
        android:background="?attr/colorPrimary"
        android:layout_width="match_parent"
        android:layout_height="48dp" />
</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/content_home"
    />

<include
    android:id="@+id/inc_bot_nav"
    layout="@layout/bottom_nav"
  />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

First Image showing the running application Second image showing the code in android design

As you can see from the images and XML seems every thing should be OK. What Is wrong with my code? any help thanks

Upvotes: 0

Views: 374

Answers (1)

sanoJ
sanoJ

Reputation: 3128

You must use android:text="@string/sort" instead of tools:text="@string/sort" in your TextView

According to docs

You can insert sample data in your layout preview by using the tools: prefix instead of android: with any attribute from the Android framework. This is useful when the attribute's value isn't populated until runtime but you want to see the effect beforehand, in the layout preview.

For example, if the android:text attribute value is set at runtime or you want to see the layout with a value different than the default, you can add tools:text to specify some text for the layout preview only.

Upvotes: 1

Related Questions