I have made a login page and in it there are two fields, one for username and one for password, and
I can't seem to figure out a way to add padding to hints so the hints in the field look like this
and if I add the android:paddingTop="30dp"
it looks like this
this EditText is using a background source (field_bg) and also a user icon which changes its colors when the field is selected (custom_username_field).
here is the xml code for the username field.
<EditText
android:id="#+id/usernameField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autofillHints=""
android:background="#drawable/field_bg"
android:cursorVisible="false"
android:drawableStart="#drawable/custom_username_field"
android:drawablePadding="-30dp"
android:ems="10"
android:fontFamily="#font/staatliches"
android:hint="USERNAME"
android:includeFontPadding="true"
android:inputType="textPersonName"
android:textAlignment="center"
android:textColor="#6E6E6E"
android:textSize="20sp"
android:paddingTop="30dp"
app:boxStrokeWidth="#null"
app:boxStrokeWidthFocused="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.507"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.421"
tools:ignore="TouchTargetSizeCheck" />
there is a poor solution to this problem:
android:textAlignment="center"
android:gravity="top"
tools:ignore="RtlCompat"
But in this case, the text that the user will enter will replace the hint and will be at the very top, which will not look nice. It would be possible to change the position of the text after the user has entered the text but for this you need to switch to code, not XML.
I also suspect that you plan to leave a prompt even after the user enters the text.
create hint in string.xml and then use in view
<EditText android:hint="#string/yourhint" />
You can try like this.
<EditText
android:id="#+id/usernameField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_10_background3"
android:drawableStart="#drawable/aa"
android:drawableTint="#color/white"
android:ems="10"
android:fontFamily="#font/caveat_semi_bold"
android:hint="USERNAME"
android:inputType="textPersonName"
android:padding="20dp"
android:textAlignment="center"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="20sp"
app:boxStrokeWidth="#null"
app:boxStrokeWidthFocused="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.507"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.421"
tools:ignore="TouchTargetSizeCheck" />
Related
Let me try to explain the title.
I have a manufacturer TextView that is populated from MYSQL. When a manufacturer is selected it populates the Model TextView.
Now I want to add OTHER in each model, and when it is selected an EditText appears. Something like this:
-FORD
---Mustang
---Escape
---Other
-BMW
---X5
---Z4
---Other
Now whenever Other is selected, the EditText appears. If not, then it remains hidden.
The only way I got it working is by creating a field in mysql for each model. I am hoping there is a better approach.
Here is what I have done.
enter code here
<EditText
android:id="#+id/fordTextView"
android:layout_width="0dp"
android:layout_height="130px"
android:layout_marginStart="16dp"
android:visibility="gone"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#drawable/custom_progress_bar_horizontal"
android:inputType="textPersonName"
android:paddingStart="#dimen/space_12"
android:hint="#string/item_entry__model"
android:paddingLeft="#dimen/space_12"
android:paddingTop="8dp"
android:paddingEnd="#dimen/space_12"
android:paddingRight="#dimen/space_12"
android:paddingBottom="8dp"
android:textAlignment="viewStart"
android:textColor="#color/text__primary"
android:textSize="14sp"
app:font='#{"normal"}'
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/plateNumTextView" />
<EditText
android:id="#+id/bmwTextView"
android:layout_width="0dp"
android:layout_height="130px"
android:layout_marginStart="16dp"
android:visibility="gone"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#drawable/custom_progress_bar_horizontal"
android:inputType="textPersonName"
android:paddingStart="#dimen/space_12"
android:hint="#string/item_entry__model"
android:paddingLeft="#dimen/space_12"
android:paddingTop="8dp"
android:paddingEnd="#dimen/space_12"
android:paddingRight="#dimen/space_12"
android:paddingBottom="8dp"
android:textAlignment="viewStart"
android:textColor="#color/text__primary"
android:textSize="14sp"
app:font='#{"normal"}'
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fordTextView" />
Here is is the java
if (itemViewModel.holder.model_id.equals(Constants.MODEL_FORD_OTHER)){
binding.get().fordTextView.setVisibility(View.VISIBLE);
binding.get().bmwTextView.setVisibility(View.GONE);
}
if (!itemViewModel.holder.model_id.equals(Constants.MODEL_FORD_OTHER)){
binding.get().fordTextView.setVisibility(View.GONE);
binding.get().fordTextView.setText("");
}
if (itemViewModel.holder.model_id.equals(Constants.MODEL_BMW_OTHER)){
binding.get().bmwTextView.setVisibility(View.VISIBLE);
binding.get().fordTextView.setVisibility(View.GONE);
}
if (!itemViewModel.holder.model_id.equals(Constants.MODEL_BMW_OTHER)){
binding.get().bmwTextView.setVisibility(View.GONE);
binding.get().bmwTextView.setText("");
}
Is there a way of doing this by using only one EditText?
You can achieve this using single EditText, when ever click is registered for particular model Other button, set the model_id of that model as tag to the EditText. And while reading input from EditText, always check for tag to get the model_id
binding.get().modelTextView.setTag(""+itemViewModel.holder.model_id);
I am trying to make the comments section the same as Instagram for edit text. My requirement is to show send as imeOptions with multiline typing and expanding the edit text.
This is what I tried, it starts typing in the next line but the edit text not expanding.
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/etComment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:hint="Add comment here..."
android:imeOptions="actionSend"
android:inputType="textCapSentences"
android:lineSpacingExtra="2dp"
android:lineSpacingMultiplier="1.2"
android:maxHeight="#dimen/margin_100"
android:maxLength="200"
android:maxLines="10"
android:singleLine="false"
android:textColor="#color/white"
android:textColorHint="#color/hint_color"
android:textSize="14sp" />
Your XML is nearby correct. Please add inputType = 'text' as well.
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/etComment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:hint="Add comment here..."
android:inputType="text|textCapSentences"
android:imeOptions="actionSend"
android:lineSpacingExtra="2dp"
android:lineSpacingMultiplier="1.2"
android:maxHeight="#dimen/margin_100"
android:maxLength="200"
android:singleLine="false"
android:textColor="#color/white"
android:textColorHint="#color/hint_color"
android:textSize="14sp" />
Also, in activity class
etComment.setHorizontallyScrolling(false);
etComment.setMaxLines(Integer.MAX_VALUE);
Let me know, if that works.
you need to catch text change and change the height manually according the number of lines entered by user for expanding or sharing
I'm facing an issue regarding EditText.
EditText is not working in couple of android devices when inputType:Text / TextMultiline/ TextPersonName.
but when you use inputType:Number
It works in all devices
what is the issue?
<EditText
android:id="#+id/quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Quantity 1Kg Meat etc"
android:focusableInTouchMode="true"
android:textIsSelectable="true"
android:clickable="true"
android:inputType="text"
android:textSize="14sp"
android:textColor="#android:color/black"
android:textColorHint="#android:color/black"
android:layout_below="#+id/line1"
android:layout_alignParentStart="true" />
Firstly it didn't show the keyboard
then i use this
android:windowSoftInputMode="stateVisible|adjustResize"
after this i can't edit the text fields
if inputType:number then it works
One thing i want to add more is i'm using this in custom ListView
I think problem with android:textIsSelectable="true" try to remove and check
<EditText
android:id="#+id/quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Quantity 1Kg Meat etc"
android:focusableInTouchMode="true"
android:clickable="true"
android:inputType="text"
android:textSize="14sp"
android:textColor="#android:color/black"
android:textColorHint="#android:color/black"
android:layout_below="#+id/line1"
android:layout_alignParentStart="true" />
android:inputType="textNoSuggestions|text"
android:focusable="true"
Working solution
If mobile text prediction is on then use above inputType to edit textfields
Can someone point me on how to limit the edittext as one line only?
screenshot:
my xml:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:id="#+id/textView_data2"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:maxLines="1"
android:gravity="fill_vertical" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:scrollHorizontally="false"
android:id="#+id/textView_data2"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:maxLines="1"
android:inputType="textPersonName"
android:gravity="fill_vertical" />
Just add into your XML-File android:maxLines="1"
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:id="#+id/textView_data2"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:inputType="text"
android:imeOption="actionNext"
android:gravity="fill_vertical" />
android:inputType="text"
android:imeOption="actionNext"
these two lines are the catch. you better use actionDon in imeOption
i.e.,
android:imeOption="actionDone"
use this and you are all good :)
P.S. there are multiple types of imeOption provided by android. We usually use these imeOptions for our softKeyboardInput where we need to change enter button of our keypad to anything else.
e.g., actionDone : DOne button
actionNext :Go to next editBox and etc,
These imeOption only works with inputType="text|number|..i.e. you need to specify a input type for using imeOption.
Hope it will help you :)
I have a TextView in my layout:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="Hello"
/>
textAllCaps works good, no problem. But when I try to make text selectable by adding textIsSelectable
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textIsSelectable="true"
android:text="Hello"
/>
textAllCaps not working. It seems like these two attributes can't work together properly. Have you any suggestions why it happens and how to make text both all caps and selectable (I'm interested in a most clear way, not setting text change listener and capitalizing text manually). I'll be appreciate for any suggestions, thank you.
Can you try this in Activity :
edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
I found one solution. It's to use AppCompatTextView and app:textAllCaps:
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:textAllCaps="true"
android:textIsSelectable="true"
android:text="Hello"
/>
I'm not sure this is the best solution (AppCompatTextView docs tells to use this component only when creating custom components), but it works.
You can set inputType property as "textCapCharacters" for Uppercase keyboard as default
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapCharacters"
/>
use like this
<android.support.design.widget.TextInputLayout
android:id="#+id/input_postcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapCharacters" //use this line dont forgot
android:textColorHint="#color/white"
app:hintTextAppearance="#style/TextAppearance.App.TextInputLayout">
<EditText
android:id="#+id/et_postcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:backgroundTint="#color/white"
android:gravity="center_vertical"
android:hint="Post code "
android:inputType="text" //dont use hereinputtype
android:imeOptions="actionNext"
android:maxLength="4"
android:padding="10dp"
android:textAllCaps="true"
android:singleLine="true"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="15sp" />
</android.support.design.widget.TextInputLayout>