【问题标题】:How to set the button color in Vertical Layout in Anko如何在 Anko 的垂直布局中设置按钮颜色
【发布时间】:2018-05-21 07:01:37
【问题描述】:

我正在尝试使用 Anko 垂直布局的登录表单。尝试更改按钮的背景和文本颜色,如下所示。但它不起作用。

class LoginActivity : AppCompatActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    LoginActivityUI().setContentView(this)   } }

class LoginActivityUI : AnkoComponent<LoginActivity> {

  override fun createView(ui: AnkoContext<LoginActivity>) = with(ui) {
    verticalLayout {
      padding = dip(22)
      var userName = editText()
      userName.hint = "Enter UserName"

      var passWord = editText()
      passWord.hint = "Enter Password"

      var button = button {
        backgroundColor = R.color.colorPrimary
        text = "SignIn"
        textColor = android.R.color.white
      }

    }   
}

}

【问题讨论】:

    标签: android kotlin anko anko-component


    【解决方案1】:

    终于找到了问题的答案:

    backgroundColor = ContextCompat.getColor(context,R.color.colorPrimary)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-29
      • 2011-07-18
      • 1970-01-01
      • 2020-12-08
      • 2012-07-04
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      相关资源
      最近更新 更多