您可以在TextView上设置图形布局仅预览文本吗? [英] Can you set graphical layout preview-only text on a TextView?

查看:124
本文介绍了您可以在TextView上设置图形布局仅预览文本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个样式化的TextView,其真实文本在运行时动态填充.图形布局视图对于在外观和感觉等方面了解该组件如何与其他组件一起使用非常有用.此文本字段没有明智的默认设置,我希望在填充之前将其保留为空白.如果我未在TextView声明中指定任何文本,则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?

我正在使用Eclipse ADT.

I'm using Eclipse ADT.

推荐答案

是的,您可以使用Android Studio中的设计工具扩展属性.

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

查看此页面 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" />

这实际上适用于大多数(如果不是全部xml属性).

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

例如

tools:visibility="gone"

将预览可见性设置为已消失",但运行时可见性将保持不变.

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

这篇关于您可以在TextView上设置图形布局仅预览文本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆