【发布时间】:2021-04-09 12:57:26
【问题描述】:
我想在一个线性布局中动态添加 TextInputLayout。我可以在 linearLayout 中添加 TextView 和 EditText,但不能添加 TextInputLayout。 那是我的线性布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:id="@+id/userInformation_lnr">
我可以使用以下代码块添加 TextView 和 EditText
LinearLayout ll = (LinearLayout) findViewById(R.id.userInformation_lnr);
for(int i = 0; i <oyuncuSayisi; i++ ){
EditText et = new EditText(this);
TextView tx = new TextView(this);
tx.setText("Player "+(i+1));
tx.setTextSize(19);
tx.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD_ITALIC));
tx.setTextColor(this.getResources().getColor(R.color.silver));
et.setHint((i+1)+".Enter Player Name");
et.setHintTextColor(this.getResources().getColor(R.color.DarkGoldenrod));
DrawableCompat.setTint(et.getBackground(), ContextCompat.getColor(this, R.color.silver));
et.setTextColor(this.getResources().getColor(R.color.SteelBlue));
et.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD_ITALIC));
et.setTextSize(17);
et.setId((i+1));
ll.addView(tx);
ll.addView(et);
}
但我不知道如何添加TextInputLayout,如何在LinearLayout里面添加TextInputLayout?
【问题讨论】:
-
同理。你有什么问题?
-
不知道怎么添加TextInputLAyout
-
您当然可以将 TextInputLayout 添加到 LinearLayout 中,但 TextInputLayout 仅在具有 TextInputEditText 的子项时才有效。因此,将 TextInputLayout 添加到您的 LinearLayout,并将 TextInputEditText 添加到 TextInputLayout。也许这是你的问题?
-
我添加了 TextInputLayout 但如何添加样式?
标签: android android-linearlayout android-textinputlayout