Android, EditText, prevent line wrapping - android

I have an EditText component:
<EditText
android:id="#+id/LogDisplay"
android:layout_width="0dp"
android:layout_height="0dp"
android:ems="10"
android:fadeScrollbars="true"
android:gravity="start|top"
android:importantForAutofill="no"
android:inputType="textMultiLine|textNoSuggestions"
android:isScrollContainer="true"
android:nestedScrollingEnabled="true"
android:overScrollMode="always"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideInset"
android:scrollbars="horizontal|vertical"
android:scrollHorizontally="true"
android:singleLine="true"
android:verticalScrollbarPosition="right"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="LabelFor,SpeakableTextPresentCheck" />
Can't get the result to show a horizontal scroll bar and lines of text to show full length without hyphens.
Help me please.

To add a horizontal scroll to edit text, add this to your edit text:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/et_name_signup"
android:paddingLeft="5dp"
android:layout_marginTop="2dp"
android:singleLine="true"
android:background="#android:color/transparent"
android:scrollHorizontally="true"/>

Related

Set hint on top of TextInputEditText in TextInputLayout

How to set hint of TextInputEditText on top of view.
I have the following edit text that user will type description of the product, but hint is on center of view.
Here is the XML code.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/interestDescriptionView"
style="#style/TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:maxLines="5"
app:layout_constraintBottom_toTopOf="#+id/tagsView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleView"
app:layout_constraintVertical_chainStyle="packed">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/interestDescriptionEditTextView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:textAlignment="viewStart"
android:hint="Descrição *"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>
You can set android:minLines to 2 or greater .. this will make it work
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/interestDescriptionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Descrição *"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textview"
app:layout_constraintVertical_chainStyle="packed">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/interestDescriptionEditTextView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:gravity="top"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="textMultiLine|textCapSentences"
android:maxLines="5"
android:minLines="2"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
Also you can check other workarounds from here

EditText TextInputLayout Hint text alignment: Is there a way to align hint text like textAlignment property of EditText view

I have an inputText field(TextInputLayout's EditText) of fixed height.
I want to align hint text to top left of the view.
Problem: hint text is always displayed at center_verticle but I want to display it at top left corner.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/aboutWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<EditText
android:id="#+id/et_about_sponsor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_medium" />
</com.google.android.material.textfield.TextInputLayout>
As per this github issue you need to set android:minLines to at least 2 along with android:gravity="top".
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/txtInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Hint">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/et_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
**android:minLines="2"**
/>
</com.google.android.material.textfield.TextInputLayout>
You can use:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<com.google.android.material.textfield.TextInputEditText
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
.../>
</com.google.android.material.textfield.TextInputLayout>
Try to add style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style to the TextInputLayout
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/aboutWrapper"
android:layout_width="match_parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<EditText
android:id="#+id/et_about_sponsor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_medium" />
</com.google.android.material.textfield.TextInputLayout>
You can use
<EditText
android:id="#+id/editTextTextPersonName5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:hint="Message"
android:gravity="left|top"
android:inputType="textAutoComplete"
android:textAlignment="textStart" />
Here gravity attribute will help in aligning the text to whichever you want.
You can Refer Here

How to set some views into TextInputLayout on Android

In my application i want show views into TextInputLayout.
I want show EditText, TextView (for show countDownTimer) and View (for show line)!
Such as Below Image :
I write below codes, but i can show just EditText and i can't show any other views, such as TextView and View!
My XML codes :
<android.support.design.widget.TextInputLayout
android:id="#+id/signInFrag_phoneInpLay"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="8dp"
app:boxStrokeColor="#color/colorAccent"
app:boxStrokeWidth="1dp">
<EditText
android:id="#+id/edtLogin1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:drawableEnd="#drawable/ic_phone"
android:drawableRight="#drawable/ic_phone"
android:gravity="right|center_vertical"
android:hint="Phone Number"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColorHint="#c0c0c0"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
How can i change my code for show such as above image?
You can set view as overlap on textInputLayout by constraintLayout. May be it has risk to overlap editText`s text with count text or vertical view. But i found in your text view has text limit. so For your reason it is not possible overlap the count text view.
Code **
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search Page"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/input_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:boxStrokeColor="#color/colorAccent"
app:boxStrokeWidth="1dp"
app:hintEnabled="true"
app:layout_constraintTop_toBottomOf="#+id/title">
<EditText
android:id="#+id/edtLogin1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:drawableStart="#drawable/ic_action_profile"
android:gravity="left|center_vertical"
android:hint="Phone Number"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColorHint="#c0c0c0"
android:textSize="12sp" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/text_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22sec"
app:layout_constraintBottom_toBottomOf="#+id/input_layout"
app:layout_constraintEnd_toEndOf="#+id/input_layout"
app:layout_constraintTop_toTopOf="#+id/input_layout" />
<View
android:id="#+id/view"
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="#color/colorPrimary"
app:layout_constraintBottom_toBottomOf="#+id/input_layout"
app:layout_constraintEnd_toStartOf="#+id/text_view_time"
app:layout_constraintTop_toTopOf="#+id/input_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>

Android textview scrollable horizontal

I want to scroll text but It doesn't scroll and I used this code but it doesn't work. I tried other codes but still not working
<android.support.v7.widget.AppCompatTextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Some text "
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
and this in Adapter class
if (tv.getText().toString().length() > tv.getMaxLines())
tv.setSelected(true);
Try this, hope it may helps you.
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollHorizontally="true"
android:text="Horizontal scroll view will work now"/>
</HorizontalScrollView>

Display only single line at a time, in a Multiline Edittext

I have tried android:singleLine, maxLines, lineSpacing attributes but my EditText always displays a part of next line. How can I force it to display a single line at a time?
<EditText
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/formulaView"
android:textColor="#000000"
android:textCursorDrawable="#drawable/visible_cursor"
android:background="#ffffff"
android:layout_marginTop="1dp"
android:textSize="18sp"
android:maxHeight="30dp"
android:gravity="center_vertical"
android:layout_marginBottom="1dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:scrollbars="vertical"
android:imeOptions="actionNext"
android:completionThreshold="1"
android:inputType="textMultiLine|textNoSuggestions"/>
Don't Use
android:inputType="textMultiLine|textNoSuggestions"
Instead use:
android:inputType="textNoSuggestions"
Code:
<EditText
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/formulaView"
android:textColor="#000000"
android:background="#ffffff"
android:layout_marginTop="1dp"
android:textSize="18sp"
android:text="=SUM(android,Hello,How,Are,You) GoodMorining"
android:maxHeight="30dp"
android:gravity="center_vertical"
android:layout_marginBottom="1dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:scrollbars="vertical"
android:imeOptions="actionNext"
android:completionThreshold="1"
android:singleLine="true"
android:inputType="textNoSuggestions"/>
Hope this will help.
Have a great day ahead.

Categories

Resources