Android xml中tools命名空间用途示例

来源:互联网 发布:kindle oasis 知乎 编辑:程序博客网 时间:2024/06/05 05:09

tools命名空间可以覆盖组件的任何属性,以便在AndroidStudio预览中进行不同的展示。

以下面的代码为例,TextView具有text属性,我们可以用tools:text覆盖该属性,以提供初值,
于是通过预览,在应用运行前就能知道界面大致的样子。

在应用实际运行时,tool:text提供的字段,并不会显示出来。

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    <!--声明tools命名空间 -->    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:gravity="center"    tools:context="stark.a.is.zhang.quizgeo.CheatActivity">    <TextView        android:id="@+id/answerTextView"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:padding="@dimen/text_view_padding"        <!--看这里-->        tools:text="Answer"/></LinearLayout>
0 0
原创粉丝点击