我想创建一个像这样的材料编辑文本字段:
这就是我创建编辑文本字段的方式:
TextInputLayout textInputLayout = new TextInputLayout(MainActivity.this);
textInputLayout.setHint("name:");
TextInputEditText editText = new TextInputEditText(MainActivity.this);
editText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
editText.setTypeface(Typeface.create("sans-serif-smallcaps", Typeface.NORMAL));
editText.setScaleX(0.99f);
textInputLayout.addView(editText);
textInputLayout.setBoxBackgroundMode(TextInputLayout.BOX_BACKGROUND_OUTLINE);
textInputLayout.setBoxCornerRadii(10, 10, 10, 10);
textInputLayout.setPadding(10, 10, 10, 10);
textInputLayout.setBoxStrokeWidth(2);
layout.addView(textInputLayout);
如您所见,我得到的编辑文本字段没有任何边框。我该如何解决这个问题?
我试过了
textInputLayout.setBoxBackgroundMode(TextInputLayout.BOX_BACKGROUND_FILLED);
,结果还是一样
同样的问题已经在下面的链接中得到了回答,
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" 实施 'com.android.support:design:28.0.0-alpha1'
<android.support.design.widget.TextInputLayout
android:id="@+id/name_text_input"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label_name" />
</android.support.design.widget.TextInputLayout>