Skip to content

Instantly share code, notes, and snippets.

@serhatleventyavas
Created November 9, 2020 08:32
Show Gist options
  • Save serhatleventyavas/43abb54acea9a995d27cb1ce3b2dca4d to your computer and use it in GitHub Desktop.
Save serhatleventyavas/43abb54acea9a995d27cb1ce3b2dca4d to your computer and use it in GitHub Desktop.
TextInputLayout Kotlin Example
val relativeLayout = view.findViewById<RelativeLayout>(R.id.edit_profile_relative_layout)
val emailTextInputLayout = TextInputLayout(requireContext(), null, R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox)
val emailTextInputLayoutParams : LinearLayout.LayoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
emailTextInputLayout.hint = "Please Enter Email Address"
emailTextInputLayout.boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_OUTLINE
emailTextInputLayout.setBackgroundColor(Color.WHITE)
emailTextInputLayoutParams.setMargins(0,0,0,10)
emailTextInputLayout.layoutParams = emailTextInputLayoutParams
emailTextInputLayout.setBoxCornerRadii(5f, 5f, 5f, 5f)
val edtEmail = TextInputEditText(emailTextInputLayout.context)
val edtEmailParams: LinearLayout.LayoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
edtEmail.compoundDrawablePadding = 10
edtEmail.inputType = InputType.TYPE_CLASS_PHONE
edtEmail.imeOptions = EditorInfo.IME_ACTION_DONE
edtEmail.layoutParams = edtEmailParams
emailTextInputLayout.addView(edtEmail)
relativeLayout.addView(emailTextInputLayout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment