Kotlin Android 绑定视图xml

2017-10-31  本文已影响517人  这个杀手不太累

在Android Studio3.0中默认支持使用Kotlin来编写Android程式。
在用Kotlin写的Activity绑定视图文件中不需要使用findViewById,让我们看下如何使用Kotlin绑定视图。

```

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World"
    android:textAllCaps="false" />

</RelativeLayout>
```
上一篇 下一篇

猜你喜欢

热点阅读