rey5137 / material

A library to bring fully animated Material Design components to pre-Lolipop Android.
http://rey5137.com/material/
Apache License 2.0
6k stars 1.32k forks source link

Multiline Edittext not working #184

Open SureshCS-50 opened 9 years ago

SureshCS-50 commented 9 years ago

I am creating my Edittext through code.. like..

EditText editText = (EditText) inflater.inflate(R.layout.material_edittext, null);
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
editText.setHint("hint");
editText.setHintTextColor(getActivity().getResources().getColor(R.color.erx_textbox_hint));

now i need to make this as multi line support.. I don't know how to do it..

thanhthang90 commented 9 years ago

try this, it worked for me.

    <com.rey.material.widget.EditText
        android:id="@+id/etContent"
        style="@style/Material.Widget.EditText.Light"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="top|left"
        android:hint="Your content here"
        android:inputType="textMultiLine"
        android:lines="6"
        android:maxLines="7"
        android:minLines="5"
        android:scrollbars="vertical"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Body1"
        app:et_inputId="@+id/etContent"
        app:et_supportMode="none" />

Note: add this line: xmlns:app="http://schemas.android.com/apk/res-auto" to your parent layout

SureshCS-50 commented 9 years ago

Fine, I override that EditText's mInputView.. and it is working great.. :)

Now in my code like earlier just by doing editText.setSingleLine(false); will make my editText multiline support.

public class CustomEditText extends EditText {

    public CustomEditText(Context context) {
        super(context);
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void setSingleLine(boolean singleLine){
        mInputView.setSingleLine(singleLine);
    }
}