如何为 Material Design 的 TextInputLayout 添加值(setText)?

huangapple go评论68阅读模式
英文:

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:

&lt;com.google.android.material.textfield.TextInputLayout
     android:id=&quot;@+id/barcodeAdd&quot;
     android:layout_width=&quot;match_parent&quot;
     android:layout_height=&quot;wrap_content&quot;   
                   
     style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;

      &lt;com.google.android.material.textfield.TextInputEditText
           android:layout_width=&quot;match_parent&quot;
           android:layout_height=&quot;wrap_content&quot;
           android:hint=&quot;Bar Code&quot;/&gt;

&lt;/com.google.android.material.textfield.TextInputLayout&gt;

答案1

得分: 19

以下是翻译好的内容:

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

mTextInputLayout.getEditText().setText("你的文本");

mTextInputLayout.getEditText().getText()
英文:

this is the syntax.. use it as appropriate in you code:

mTextInputLayout.getEditText().setText(&quot;ur text&quot;);

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(&quot;you Text&quot;))

huangapple
  • 本文由 发表于 2020年5月4日 21:34:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/61593503.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定