I have an Edittext wrapped inside a TextInputLayout. I tried using android:nextFocusForward="#+id/spinnerLanguage" so that i could gain the focus of the spinner. This doesn't work. I even tried using android:nextFocusUp and this method does not seem to work
<android.support.design.widget.TextInputLayout
android:id="#+id/txtEmailAddressWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:hint="EMAIL ADDRESS"
android:padding="5dp"
android:id="#+id/txtEmailAddress"
android:nextFocusForward="#+id/spinnerLanguage"
android:inputType="text"
android:maxLength="40" />
</android.support.design.widget.TextInputLayout>
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/spinnerLanguage"
android:layout_width="match_parent"
app:ms_floatingLabelColor="#color/colorAccent"
android:layout_height="wrap_content"
app:ms_enableFloatingLabel="true"
app:ms_hint="LANGUAGE" />
try with this
txtEmailAddress.setFocusableInTouchMode(true);
or
txtEmailAddress.setFocusable(false);
and use this to clear focous
txtEmailAddress.clearFocus();
or use this in xml
android:focusable="true"
android:focusableInTouchMode="true"
may be this will help you
when i put 2 or 3 TextInputLayout, label seams link graphically to previous editText instead of next. i need to put much marginTop to TextInputLayout. there is any possibility to approach label with EditText?
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name"
android:inputType="textCapWords" />
</android.support.design.widget.TextInputLayout>
in this example we can see margin from hint and edittext
Changing the paddingTop of the EditText should fix it, for example:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="0dp"
android:hint="#string/name"
android:inputType="textCapWords" />
</android.support.design.widget.TextInputLayout>
You can definitely add properties to TextInputLayout however you want it to be. Following will help you to add marginTop from exactly above Viewof TextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name"
android:inputType="textCapWords" />
</android.support.design.widget.TextInputLayout>
I designed a layout with four EditText and i want to facilitate the navigation of them. I understand the use of android:nextFocusDown but i'm not able to get it to work. I also setted the ´ImeOptions´ to actionNext, but on the softpad I neither see the right icon.
My XML snippet:
<EditText
android:id="#+id/reservation_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#drawable/edit_text_reservation"
android:ems="10"
android:hint="#string/yourName"
android:imeOptions="actionNext"
android:nextFocusDown="#+id/reservation_surname" >
</EditText>
<EditText
android:id="#+id/reservation_surname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#drawable/edit_text_reservation"
android:ems="10"
android:hint="#string/yourSurname"
android:imeOptions="actionNext"
android:nextFocusDown="#+id/reservation_email"
android:nextFocusUp="#+id/reservation_surname" />
<EditText
android:id="#+id/reservation_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#drawable/edit_text_reservation"
android:ems="10"
android:hint="#string/yourEmail"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:nextFocusDown="#+id/reservation_notes"
android:nextFocusUp="#+id/reservation_email" />
<EditText
android:id="#+id/reservation_notes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_text_reservation"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textMultiLine"
android:nextFocusUp="#id/reservation_notes" />
I had a similar issue, where nextFocus* simply did not work. In your case..
going from
<EditText android:id="#+id/reservation_name"...
android:nextFocusDown="#+id/reservation_notes"
to
change surname's id to NOT have a "+" i.e.
<EditText android:id="#id/reservation_surname"
this way you are
no creating a new reference to that tag.
This will now work.
How do I display a TextArea for my android project? From xml, the only choice is TextField, multi lined. But thats editable. I need a TextArea which is only for displaying messages/text can't be edit/input by the user.
Try this:
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="150dp"
android:inputType="text|textMultiLine"
android:gravity="top"/>
Use TextView inside a ScrollView
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="150dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
If you do not want to allow user to enter text TextView is the best option here. Any how you can also add EditText for this purpose. here is a sample code for that.
This would automatically show scrollbar if there is more text than the specified lines.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="8"
android:maxLines="10"
android:minLines="6"
android:scrollbars="vertical" />
Edit: Adding attributes below to textView would make it a textArea that would not be editable.
android:lines="8"
android:maxLines="10"
android:minLines="6" // optional
Its really simple, write this code in XML:
<EditText
android:id="#+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="First Name"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="160dp"
android:ems="10"
android:gravity="left|top"
android:hint="Write your comment.."
android:inputType="textMultiLine"
android:textSize="15sp">
<requestFocus />
</EditText>
Use TextView inside a ScrollView to display messages with any no.of lines. User can't edit the text in this view as in EditText.
I think this is good for your requirement. Try it once.
You can change the default color and text size in XML file only if you want to fix them as below:
<TextView
android:id="#+id/tv"
android:layout_width="fill_parent"
android:layout_height="100px"
android:textColor="#f00"
android:textSize="25px"
android:typeface="serif"
android:textStyle="italic"/>
or if you want to change dynamically whenever you want use as below:
TextView textarea = (TextView)findViewById(R.id.tv); // tv is id in XML file for TextView
textarea.setTextSize(20);
textarea.setTextColor(Color.rgb(0xff, 0, 0));
textarea.setTypeface(Typeface.SERIF, Typeface.ITALIC);
<EditText
android:id="#+id/comments_textbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="comments"
android:inputType="textMultiLine"
android:longClickable="false" />
use it to create multi line text box like textArea in Html
Defining an Android Mulitline EditText Field is done via the inputType=”textMultiline”. Unfortunately the text looks strangely aligned. To solve that also use the gravity=”left|top” attribute.
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:gravity="left|top"
android:inputType="textMultiLine" >
<requestFocus />
check this vogella blog
All of the answers are good but not complete. Use this.
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:background="#drawable/text_area_background"
android:gravity="start|top"
android:hint="#string/write_your_comments"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="textMultiLine"
android:padding="12dp" />
this short answer might help someone who is looking to do.
add this simple code in your code
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:focusable="false"
android:singleLine="true" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="100dp">
<EditText
android:id="#+id/question_input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:inputType="text|textMultiLine"
android:lineSpacingExtra="5sp"
android:padding="5dp"
android:textAlignment="textEnd"
android:typeface="normal" />
</android.support.v4.widget.NestedScrollView>
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/border_layout"
android:inputType="text|textMultiLine"
android:gravity="top"/>
Create a Drawable Resource file called border_layout
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#color/custom_grey" />
</shape>
custom grey color under values->colors.xml
<color name="custom_grey">#494646</color>
In my code,am having EdiText and its code is:
<EditText
android:layout_height="150dp"
android:id="#+id/profiledescription"
android:imeOptions="actionDone|flagNoExtractUi"
android:textSize="16sp"
android:paddingLeft="20dp"
android:layout_width="fill_parent"
android:enabled="false"
android:layout_marginRight="20dp"></EditText>
But the problem is cursor is starting from middle rather than usual first position:
You'll probably need to set android:gravity="top" for the corresponding XML-element in the layout.
Try specifying the following in your EditText XML declaration:
<EditText android:gravity="left|top" ... />
Hope this helps!
You need to add android:gravity="top" to the layout for that EditText.
<EditText
android:layout_height="150dp"
android:id="#+id/profiledescription"
android:imeOptions="actionDone|flagNoExtractUi"
android:gravity="top"
android:textSize="16sp"
android:paddingLeft="20dp"
android:layout_width="fill_parent"
android:enabled="false"
android:layout_marginRight="20dp">
</EditText>
Use the following:
android:gravity="top" android:singleLine="false"