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

有些话、适合烂在心里 提交于 2019-11-27 01:16:01

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/20599775/can-you-set-graphical-layout-preview-only-text-on-a-textview

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