8

I have an application that uses a lot of textinputlayouts because I like the style they create

on one screen I am showing info on one object and I want it too look like the data the user entered with the textinputedittexts , small caption above and the data below

right now I have a textinputlayout with a disabled textinputedittext below

is there a way to just have a textview under the textinputlayout that will be shown in the same style?

thanks in advance for any help you can provide

edit:

as a side note here's what I am currently using to disable the edittext fully

<android.support.design.widget.TextInputLayout
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/name"
        tools:text="This is where the name goes"
        android:inputType="none"
        android:clickable="false"
        android:cursorVisible="false"
        android:focusable="false"
        android:focusableInTouchMode="false" />

what I am trying to avoid is not use clickable and inputtype etc etc in EVERY view that I'm trying to create, and instead use a single view

so other than creating a custom edittext (like NeverEnabledEditText) that starts unclickabke in every way, or add all those attributes to my xml, is there a way to do the above?

Cruces
  • 3,029
  • 1
  • 26
  • 55
  • This might help you https://stackoverflow.com/questions/30953449/design-android-edittext-to-show-error-message-as-described-by-google – Bharat Jun 05 '17 at 10:31
  • Possible duplicate of [Design Android EditText to show error message as described by google](https://stackoverflow.com/questions/30953449/design-android-edittext-to-show-error-message-as-described-by-google) – Bharat Jun 05 '17 at 10:32
  • 1
    no , what I want is to NOT use an eddittext as a child, I want to use a completely uneditable view (like textview) as a child – Cruces Jun 05 '17 at 11:20
  • Whats the use of keeping textview in textinputlayout ? – Bharat Jun 05 '17 at 11:26
  • 5
    to make it look similar to the textinputlayout with edittext, when the textview has data it shows a small caption and the data beneath, when there is no data it shows the caption in place of the textview – Cruces Jun 06 '17 at 09:02
  • did you ever find a solution? i want to do the same (except keep it clickable) – or_dvir Apr 17 '21 at 16:32
  • no after switching to kotlin I just created an extension function that does what I want and I call it whenever I want to disable the view ,something like `fun TextInputEditText.setEnabled(enabled:Boolean) { this.isClickable = enabled; this.focusable = enabled; }`, on a recent project that only had non editable edittexts I created two textviews one which was styled after textinputlayout's hint style and below it my normal textview (I dug up inside the material design code and found the styles) – Cruces Apr 18 '21 at 11:54

1 Answers1

0
 <com.google.android.material.textfield.TextInputLayout
    android:id="@+id/date_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="Date"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/tv_date"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:inputType="none"
        android:clickable="true"
        android:focusable="false"
        android:drawableEnd="@drawable/ic_keyboard_arrow_down_black_24dp"
        android:paddingEnd="4dp"
        android:paddingVertical="12dp"
        android:drawablePadding="4dp"
        android:textColor="@color/colorPrimary"
        tools:text="00/00/0000" />

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

Although a TextInputEditText, now you have it acting like a textview because you can't edit it but can set text to it. You're welcome !

Njuacha Hubert
  • 388
  • 3
  • 14