如何为 material 设计的 TextInputLayout 添加值 (setText)?

How to add value (setText) to a material design TextInputLayout?

如何在 android 工作室中将文本设置为 material 设计的 TextInputLayout(Material 设计)?

 //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()

上面的代码对我不起作用。

我的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="Bar Code"/>

</com.google.android.material.textfield.TextInputLayout>

这是语法..在您的代码中适当使用它:

mTextInputLayout.getEditText().setText("ur text");

mTextInputLayout.getEditText().getText()

示例:

TextInputEditText inpedit_txt;

inpedit_txt = (TextInputEditText)findViewById(R.id.id_of_input_edit_text);
inpedit_txt.setText(String.valueOf("you Text"))