2017-01-24 4 views
5

ボーダーレスボタンを作成する必要があります。 Widget.AppCompat.Button.Borderlessを設定するxmlの最も簡単な方法。私はこれを使用しようとしていますAnkoAnkoはXMLのスタイルattrに相当します

button(theme = R.style.Widget_AppCompat_Button_Borderless_Colored, text = "Send") { 
    horizontalGravity = Gravity.END 
    lparams(wrapContent, wrapContent) 
} 

しかし、効果はありません。私は間違って何をしていますか?

答えて

-1

注文が間違っています。試してみてください:

button("Your text", android.support.design.R.style.Base_Widget_AppCompat_Button_Borderless_Colored) { 
    //your params 
} 

これは私のために働いています。

+0

Kotlinは名前の付いたパラメータを持っていますので、名前を付けておくと問題は解決します。 – Antek

0

attrリソース受け入れる第三のコンストラクタのパラメータ、使用してみてください:

addView(Button(activity, null, R.attr.borderlessButtonStyle)) 

また、あなたはDSLコンポーネントとしてそれを宣言することができた:

fun ViewManager.borderlessButton(textRes: Int = 0) = 
     borderlessButton(textRes) { } 

fun ViewManager.borderlessButton(textRes: Int = 0, init: Button.()->Unit) = 
     ankoView({ Button(it, null, R.attr.borderlessButtonStyle) }, 0) { 
      if (textRes != 0) setText(textRes) 
      init() 
     } 

次に、あなたの呼び出しサイトはこのようになります:

borderlessButton(android.R.string.ok) 

あなたは、AnkoのhorizontalProgressBarメソッドを見ることができますnd HORIZONTAL_PROGRESS_BAR_FACRTORYも同様の方法で宣言されています。

関連する問題