English | 设为首页 | 加入收藏
  Android开辟运用kotline言语念】 【2019年数字钱币搬砖差价套】 【2019年上半年地脊正西节进】 【2019年什倍股:小股票阅历
当前位置: 主页 > 团购 >

Android开辟运用kotline言语念书笔记

时间:2019-10-02 09:45来源:原创 作者:locoy 点击:
????????: ?????Ctr+shift+A : ????action ?????,????convert java file to kotlin?? ?????Ctr+shift+alt+k: ??java?????????kotlin??? ????TODO ???п??

????????:

?????Ctr+shift+A : ????action ?????,????convert java file to kotlin??

?????Ctr+shift+alt+k: ??java?????????kotlin???

????TODO ???п????????activity.hello.setText(????)

????If we want to call the synthetic properties on?View?(useful in adapter classes), we should also importkotlinx.android.synthetic.main.activity_main.view.*.

????Once we do that, we can then invoke the corresponding extensions, which are properties named after the views in the XML file. For example, for this view:

????

????android:id="@+id/hello"

????android:layout_width="fill_parent"

????android:layout_height="wrap_content"

????android:text="Hello World, MyActivity"

????/>

????There will be property named?hello:

????activity.hello.setText("Hi!")

??????????????: ?http://blog.csdn.net/myliuyx/article/details/52223066?productflavor

????TODO Android flavor?????????п???

????Android Flavors

????Android Extensions plugin supports Android flavors. Suppose you have a flavor named?free?in yourbuild.gradle?file:

????android {

????productFlavors {

????free {

????versionName "1.0-free"

????}

????}

????}

????So you can import all synthetic properties for the?free/res/layout/activity_free.xml?layout by adding this import:

????import kotlinx.android.synthetic.free.activity_free.*

????TODO ??????????????????

????Under the hood

????Kotlin Android Extensions is a plugin for the Kotlin compiler, and it does two things:

????Adds a hidden caching function and a field inside each Kotlin?Activity. The method is pretty small so it doesn't increase the size of APK much.

????Replaces each synthetic property call with a function call.

????How this works is that when invoking a synthetic property, where the receiver is a Kotlin Activity/Fragment class that is in module sources, the caching function is invoked. For instance, given

????class MyActivity: Activity()fun MyActivity.a() {

????this.textView.setText(????)

????}

????a hidden caching function is generated inside MyActivity, so we can use the caching mechanism.

????However in the following case:

????fun Activity.b() {

????this.textView.setText(????)

????}

????We wouldn't know if this function would be invoked on only Activities from our sources or on plain Java Activities also. As such, we don??t use caching there, even if MyActivity instance from the previous example is the receiver.(责任编辑:admin)