Search code examples
javaandroidhinttextinputlayout

How can set Hint Text in code?


I have:

<android.support.design.widget.TextInputLayout
                    android:id="@+id/ti_amount_layout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    android:theme="@style/BlueAccentColor">

                    <EditText
                        android:id="@+id/et_amount"
                        style="@style/EditTextRedBorder"
                        android:layout_width="@dimen/product_selector_width"
                        android:background="@drawable/contacts_bg_mess"
                        android:textColorHint="@color/palette_contacts_send_mess_text"
                        android:textColor="@color/palette_black"
                        android:inputType="numberDecimal">

                    </EditText>

                </android.support.design.widget.TextInputLayout>

And I need add Hint Text, If I added hint text in xml, in EditText:

android:hint="@string/s_amount"

all nice, but if I add etAmount.setHint(R.string.s_amount); in code - String (hint text) does not popup ((, Why?


Solution

  • Set the hint to the TextInputLayout instead.

    mTextInputLayout.setHint("your hint here");