xko

2017-01-24 10 views
5

में स्टाइल एटआर के बराबर Anko मुझे सीमाहीन बटन बनाने की आवश्यकता है। Widget.AppCompat.Button.Borderless सेट करने के लिए एक्सएमएल में सबसे आसान तरीका। मैं Ankoxko

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

कोटलिन को पैरामीटर्स नाम दिया गया है, अगर आप उन्हें नाम दें तो आदेश रखने की आवश्यकता नहीं है (जैसा कि सवाल में है) – Antek

0

तीसरे निर्माता पैरामीटर, जो attr संसाधन स्वीकार करता उपयोग करके देखें:

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() 
     } 

फिर, अपने कॉल-साइट कुछ ऐसा दिखाई देगा:

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

इसके अलावा, आप एक डीएसएल घटक के रूप में यह घोषणा कर सकते हैं :

borderlessButton(android.R.string.ok) 

आप एन्को की horizontalProgressBar विधि को देख सकते हैं nd HORIZONTAL_PROGRESS_BAR_FACRTORY जिसे इसी तरह घोषित किया जाता है।

संबंधित मुद्दे

 संबंधित मुद्दे