I've made a TextInputEditText for a PasswordField with a DrawableLeft as an icon, and then i added a PasswordToggleEnabled(true) .. this operation has deleted or hiden my DrawableLeft, Here's my code:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleContentDescription="Show Password"
app:passwordToggleEnabled="true"
app:hintEnabled="false"
android:id="#+id/signupPasswordlayout"
app:passwordToggleTint="#color/edittexttint">
<android.support.design.widget.TextInputEditText
android:hint="Password"
android:id="#+id/signupPassword"
android:drawableLeft="#drawable/ic_password"
android:drawablePadding="10dp"
android:inputType="textPassword"
android:drawableTint="#color/edittexttint"
android:textSize="15sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
so , is it possible to show both ( PasswordToggle and DrawableLeft ? ) thank you!
I'd not seen this exact behavior before, but looking at the source for TextInputLayout, it does attempt to preserve the user-set drawables when it applies the placeholder drawable for the password toggle. However, like most everything else in the support libraries to which its applicable, it handles them with relative positions - i.e., start and end - rather than absolute - left and right.
The support libraries have always been notorious for breaking anything that specifies absolute directions or positions, so it's no surprise that that's the issue here, as well.
Simply change the attribute you're setting to drawableStart, instead of drawableLeft. Keep this in mind, too, for anything else involving a choice of absolute or relative positions and directions with the support libraries.
Related
So I have my textview's height set to wrap content. It displays a sports score in the format
"CHI 99 CHA 88". I have the textview match the parent for its width. I also have the score text set to a specific textsize in "sp" units.
So on smaller phones, if there are more characters in the score, or if font size (accessibility settings) is changed, there is a chance that the text will need to wrap into 2 lines. However, I would like a way to control where (in the string) it will decide to wrap the text and make a new line. It would look best in the form
"CHI 99\nCHA 88". But I prefer the text to be on the same line unless it is forced to wrap by screen size, character count, or accessibility settings, so I don't want to hardcode in a "\n" from the beginning.
So basically, is there a way to control what character the text decides to create a new line at if there is a necessity for the text to wrap onto a new line.
Thanks for any responses!
Instead of programatically calculating display sizes/characters, etc., Flow widget with two TextViews can be used control this.
An example layout:
<?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="150dp"
android:layout_height="match_parent">
<androidx.constraintlayout.helper.widget.Flow
android:layout_width="0dp"
android:layout_height="wrap_content"
app:constraint_referenced_ids="text1,text2"
app:flow_horizontalBias="0"
app:flow_horizontalGap="5dp"
app:flow_horizontalStyle="packed"
app:flow_wrapMode="chain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHI 99" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHA 88" />
</androidx.constraintlayout.widget.ConstraintLayout>
Normally, with default sizing, it looks like this:
If the views cannot fit horizontally, second TextView moves to the next line:
you can avoid line breaks by use autosize and set maxLines to 1 like this:
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="2sp"
android:maxLines="1" />
Source: https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview
You can calculate characters in one line according to screen width and add new line character after that.
In my Android App, I want to let user to type Full Name at one point to an EditText. There I need the following behaviour
1). Should NOT allow user to type invalid characters. For that I was using the following
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
2). The keyboard should have the "ActionNext" to easily move to next Field. For that I was using the following
android:imeOptions="actionNext"
But when I specify digits as above, it looses the ActionNext and instead get Enter Key (move 2nd line)...
My full xml is as follows,
<EditText
android:id="#+id/editText_FullName"
android:layout_width="300dp"
android:layout_height="40dp"
android:inputType="textCapWords"
android:maxLength="40"
android:layout_marginStart="10dp"
android:textSize="16sp"
android:typeface="normal"
android:longClickable="false"
android:lines="1"
android:scrollHorizontally="false"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:imeOptions="actionNext"/>
I found after searching in google it saying to use android:singleLine="true" to fix the issue. Yes that fix issue but this attribute is deprecated and and Android Studio suggests to use android:maxLines="1" which again NOT fix the issue and loose ActionNext in Keyboard. Basically instead of ActionNext I still see Enter key (move next line) option.
Has anyone got a solution for this. Thanks
Edits
I could use regular expression validation or register the EditText to a KeyListener. But looking for a pure xml solution.
I want to disallow the user from being able to expand the the text field as shown in the image. It should look like the Password field however both will allow the following to happen with space bar or the return key.
Text field expansion
Set your all padding to something like 2dp then set maxLines to something that wont overlap the text. Maybe 2 or if you only care for 1 line, then set singleLine=true.
Your XML for that TextView can look something like so:
<TextView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:text="Hello World"
android:id="#+id/txtSomeIdForTextView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="false"
android:padding="2dp"
android:textSize="16dp" />
Take a look at this article to get started with UI, old but still good:
https://mobiforge.com/design-development/understanding-user-interface-android-part-1-layouts
I want to know if there is any way I could customize the height of an edit text that I am using. I want it to be something similar to this picture Comment Box
This is my code so far;
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#ffe7e7e7"
android:layout_marginTop="10dp" />
I would like to also know if I could notify the user how much character they have got left to write inside that edit text. So like 100 characters left out of 1000 characters. How can I go about doing this ?
you can define lines attribute
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="5"/>
To keep count, you can add TextWatcher to you EditText
Refer:
How to use the TextWatcher class in Android?
http://developer.android.com/reference/android/text/TextWatcher.html
(we all know) There are three parts in android Switch Widget ... Text - Thumb - Track.
My question is how can we completely remove this text part if we don't want to use any text
because it's ruining the balance of the layout
You simply have to not provide any text:
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Use negative margin for the switch as follows and see if it works:
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-10dp" />
I know some people consider it a bad practice to use negative margin but right it seems to be the easiest way.
You can set margin programmatically as well based on device type.