如何使用Anko设置FloatingActionButton边框宽度

我刚刚从Java切换到Kotlin,并使用Anko来构建布局

这是我的布局:

relativeLayout { floatingActionButton { imageSource = R.drawable.kotlin_is_amazing }.lparams { width = wrapContent height = wrapContent } } 

现在的问题是如何设置app:borderWidth与Anko app:borderWidth

如果视图没有根据setBorderWidth方法,你可以通过样式来做到这一点。

  1. 声明将设置此参数的样式。

      
  2. 在一个属性中引用这个样式。

     @style/whatever 
  3. 传递这个attr作为defStyleAttr来查看构造函数。

     FloatingActionButton(context, null, R.attr.whateverRef) 
  4. 扩展Anko DSL。

     val whateverFactory = { ctx: Context -> FloatingActionButton(ctx, null, R.attr.whateverRef) } inline fun ViewManager.whateverFab() = ankoView(whateverFactory, 0, {}) inline fun ViewManager.whateverFab(configure: FloatingActionButton.() -> Unit) = ankoView(whateverFactory, 0, configure)