英文:
How to add value (setText) to a material design TextInputLayout?
问题
如何在Android Studio中将文本设置为Material Design的TextInputLayout(Material Design)?
// 设置文本值
BarCode.setText(MainPage.ResultCode.getText());
TextInputLayout BarCode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_discharge_product);
BarCode = findViewById(R.id.barcodeAdd);
BarCode.setText(MainPage.ResultCode.getText());
}
上述代码对我无效。
我的XML代码:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/barcodeAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="条形码" />
</com.google.android.material.textfield.TextInputLayout>
英文:
How do i setText to a material design TextInputLayout (Material Design) in android studio?
//setValue
BarCode.setText(MainPage.ResultCode.getText());
TextInputLayout BarCode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_discharge_product);
BarCode = findViewById(R.id.barcodeAdd);
BarCode.setText(MainPage.ResultCode.getText()
The above code did not work for me.
My xml code:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/barcodeAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Bar Code"/>
</com.google.android.material.textfield.TextInputLayout>
答案1
得分: 19
以下是翻译好的内容:
这是语法..在你的代码中适当使用它:
mTextInputLayout.getEditText().setText("你的文本");
和
mTextInputLayout.getEditText().getText()
英文:
this is the syntax.. use it as appropriate in you code:
mTextInputLayout.getEditText().setText("ur text");
and
mTextInputLayout.getEditText().getText()
答案2
得分: -1
TextInputEditText inpedit_txt;
inpedit_txt = (TextInputEditText)findViewById(R.id.id_of_input_edit_text);
inpedit_txt.setText(String.valueOf("你的文本"))
英文:
Example:
TextInputEditText inpedit_txt;
inpedit_txt = (TextInputEditText)findViewById(R.id.id_of_input_edit_text);
inpedit_txt.setText(String.valueOf("you Text"))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论