How to set the button color in Vertical Layout in Anko

688 views Asked by At

I am trying a login form using Anko vertical layout. Trying to change the background and text color of the button like below. But it is not working.

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
      }

    }   
}

}
1

There are 1 answers

0
Raja Jawahar On BEST ANSWER

At last I found the answer for the question:

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