Can you set graphical layout preview-only text on a TextView?

核能气质少年 提交于 2019-11-28 06:47:31

Yes you can with the design tools extension attributes in Android Studio.

See this page https://developer.android.com/studio/write/tool-attributes.html

Basically you define the tools namespace

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

Then use it to set your placeholder text.

<EditText 
        tools:text="John Doe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

This actually works with most (if not all xml attributes).

e.g

tools:visibility="gone"

would set the preview visibility to "gone" but the runtime visibility would be unchanged.

I don't believe there is, the only possible way is when you declare your TextView, you say after, tv.setText(""); this way you will always find it blank at runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!