Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

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

I have a styled TextView whose real text is populated dynamically at runtime. The Graphical Layout view is very useful for getting a feel on how this component works with others in terms of look and feel, etc. There is no sensible default to this text field and I wish it to be blank before being populated. If I don't specify any text in the TextView declaration then the TextView is blank. I can set the text manually using:

<TextView
     ...
     android:text="Preview text"/>

and then switch to the Graphical Layout. However, I must remember to remove this or risk it being shipped in my production version.

Is there a way to specify text which is only seen in the Graphical Layout preview but not applicable at runtime?

EDIT: I'm using Eclipse ADT.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...