我正在尝试使用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
}
}
}
}
答案 0 :(得分:1)
最后我找到了问题的答案:
backgroundColor = ContextCompat.getColor(context,R.color.colorPrimary)