Created
October 22, 2021 05:54
-
-
Save qaz10102030/ffb6e3d2932d32ff4e25f023d17ed4a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // find TextInputLayout | |
| TextInputLayout textInputLayout = findViewById(R.id.textInputLayout); | |
| // 隨意設定一個 startIcon | |
| textInputLayout.setStartIconDrawable(R.drawable.ic_check); | |
| // 從 textInputLayout 找出 icon 後隱藏 | |
| CheckableImageButton icon = textInputLayout.findViewById(R.id.text_input_start_icon); | |
| icon.setVisibility(View.GONE); | |
| // 自訂文字 | |
| TextView tv = new TextView(this); | |
| tv.setText("手機電話"); | |
| tv.setTextColor(Color.BLACK); | |
| // 從 textInputLayout 找出主布局: inputFrame | |
| FrameLayout inputFrame = ((FrameLayout) textInputLayout.getChildAt(0)); | |
| // 再從 inputFrame 找出顯示 startIcon 的 LinearLayout: startLayout | |
| LinearLayout startLayout = (LinearLayout) inputFrame.getChildAt(inputFrame.getChildCount() - 2); | |
| startLayout.setVerticalGravity(Gravity.CENTER); | |
| startLayout.addView(tv,0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment