nz_21
nz_21

Reputation: 7343

Android views never becoming invisible

I'm trying to make some of my views invisibe. Here's the XML code:


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        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_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">


    <Button
            android:text="See More Like This"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/recommender"
            tools:visibility="invisible"
            android:layout_marginEnd="24dp" android:layout_marginRight="24dp" android:layout_marginBottom="20dp"
            app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toTopOf="@+id/imageView"/>
    <TextView
            android:text="https://www.google.com"
            android:layout_width="169dp"
            android:layout_height="50dp"
            android:autoLink="web"
            android:linksClickable="true"
            android:id="@+id/urlDisplay"
            tools:visibility="invisible"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
            android:layout_marginLeft="24dp" android:layout_marginTop="101dp" android:layout_marginStart="24dp"/>

    <TextView
            android:text="TextView"
            android:layout_width="0dp"
            android:layout_height="59dp"
            android:id="@+id/comicTitle" tools:visibility="invisible"
            android:layout_marginTop="21dp" android:layout_marginBottom="21dp" app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/urlDisplay" app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="40dp"
            android:layout_marginStart="40dp" android:layout_marginEnd="40dp" android:layout_marginRight="40dp"/>

</android.support.constraint.ConstraintLayout>

There is no kotlin code except for the boilerplate. When I start up the app, all of my views are visible. I don't understand how this is happening, given that I've explicitly set them to be invisible in xml.

How can I make them invisible?

Upvotes: 1

Views: 128

Answers (4)

AADProgramming
AADProgramming

Reputation: 6345

In your xml you have set the tools:visibility="invisible" This is basically tools namespace supported in Android Studio Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features.

When you build your app, the build tools remove these attributes so there is no effect on your APK size or run-time behavior. Hence when you run the app there is no effect of these attributes.

You can read more about tools attributes in official android dev docs

As suggested in comments you should instead set android:visibility="invisible"

Upvotes: 1

Bipin Tiwari
Bipin Tiwari

Reputation: 300

You have used tools:visibility="invisible" use android:visibility="invisible" to make your view invisible.

Upvotes: 2

Sunny
Sunny

Reputation: 3265

As you are using tools

tools:visibility="invisible"

Just replace the tools with the android it start working fine

android:visibility="invisible"

Upvotes: 2

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

Read Tools attributes reference

Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources). When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior.

You should use android:visibility="invisible" instead of tools:visibility="invisible"

Upvotes: 6

Related Questions