Uni
Uni

Reputation: 187

Android Custom View preview in Android studio

I am developing a custom view & I want it displays like Google Ads view below. My view doesn't contain any text view but I still want it to have a preview like that.

Can anyone support me to a solution? Thank you!!

enter image description here

Upvotes: 0

Views: 244

Answers (1)

Mark
Mark

Reputation: 139

The "tools" namespace might be able to help you here. You can add it with a line like:

xmlns:tools="http://schemas.android.com/tools"

in your root layout. Things like tools:text will show up in the preview, but not when the app is run. So the following view:

<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        tools:visibility="visible"
        tools:text="Preview Text" />

</RelativeLayout>

will show a TextView with "Preview Text" visible in the preview, but it is actually View.GONE and has no text when run.

Upvotes: 1

Related Questions