I know there has been A LOT of talk here regarding justifying text in Android. But Android O just came out and a new feature came out with it, Text Justification. They say use the final JUSTIFICATION_MODE_INTER_WORD included with the TextView class. Along with setJustificationMode(). it does work when I use it with the English language, but it fails to work when I use it with the Hebrew language. I have it set up to:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:justificationMode="inter_word"
android:text="#string/ahahvaRabba"
android:textDirection="rtl"
/>
I also tried to put android:gravity="right" but that didnt work either.
I cant imagine that google didn't think of using it with other languages.
Related
I am working in a kotlin project, and have been searching for some documentation about the screen layout.
What i want to do is very rudimentairy i guess. I want is to put a label/prompt/text before a EditText.
In html i would program something like this:
<form>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
</form>
And get the a result like this:
First name: ___________
All i can find is a "android:hint=". But it only fills the View if there is nothing in it.
Should one add extra (plainText) elements for each label ? and how should one contstrain it to the EditText ? or is there some kind of grouping ?
Update after received answers
After reading the answers i understand that you have to roll your own solution. (I am still fighting with androidstudio because it sorts the xml elements so they are not always where i put them.)
I do not use a TextInputLayout (i hope this is allowed) which makes it all quite simple. So this is my solution for now:
We link the TextView ("Date of Birth") to the parent layout:
<TextView
android:id="#+id/dobLabel2"
android:layout_width="92dp"
android:layout_height="23dp"
android:layout_marginStart="76dp"
android:layout_marginBottom="112dp"
android:labelFor="#id/dobInputText"
android:text="Date of Birth"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
and we link the EditText to the TextView
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/dobInputText"
android:layout_width="240dp"
android:layout_height="54dp"
android:hint="Day/Month/Year"
app:layout_constraintStart_toStartOf="#+id/dobLabel2"
app:layout_constraintTop_toBottomOf="#+id/dobLabel2" />
If you play with the layout_contraints you can position the the EditText also to the left of the label.
Thanks for all the input, i think i can solve my problem now.
Android EditText (now often used as a combination of TextInputLayout containing one (and only one) TextInputEditText) can display a Hint, but only while the view has no focus/content.
If you want to provide a better description on what a particular EditText is for, for many reasons (accessibility, often neglected, is not the only one), you may want to provide an extra TextView positioned anywhere you consider it ok to add the extra information needed to better describe the EditText.
The main thing to keep in mind, is to provide this TextView with the labelFor attribute, as described in the Android documentation.
If you're reading this and wondering but why do I have to provide an extra Textview to describe, why not just use the hint, android is horrible!!!, keep in mind that the Hint is good for different reasons, but not for describing what the field is about.
E.g.: Imagine you're asking for a Date of Birth. You may be tempted to write this: (note this is a simplified version obviously):
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/dobInputLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/dobInputText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Date of Birth" />
</com.google.android.material.textfield.TextInputLayout>
And you'd be mostly ok, but then your designer comes in and says, well, we also want to show the Format that we accept, for e.g.: DAY/MONTH/YEAR...
Now you're going to change the hint to be:
android:hint="Date of Birth (DD/MM/YYYY)
And you'd again, be ok, but for accessibility users... this doesn't read very efficiently nor is very clear. You also get back from your designer who says: "but I don't want the (DD/MM/YYYY) part to be visible after the user focuses or types something..."
And so on and so forth.
The correct (according to Google, Material Design, and who knows what), is to provide an extra TextView that accompanies the TextInput combos:
(again, keep in mind this is pseudo-code, when in doubt, read the documentation)
<TextView
android:id="#+id/dobLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Birth"
android:labelFor="#id/dobInputText />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/dobInputLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/dobInputText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Day/Month/Year" />
</com.google.android.material.textfield.TextInputLayout>
Do not provide contentDescription on those views because they will likely interfere with TalkBack/Accessibility. These are the conventions that Android set in place, you may or may not like them, but this is how it's expected to be done.
Do I think EditText should be a better widget and handle this better for you? Yes. Does it matter what I think? Nope.
Yes, you have to add one more textview before adding edit text. The hint is used for displaying messages in edittext.
For Android and IOS platforms same font used. It's looking good on IOS, but android doesn't show some characters like "Ş", "Ğ" properly.The below screenshot from android.
Seems it's not font specific problem beacuse on IOS working well.
<TextView
android:id="#+id/txt_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="#font/avenirltstd_book"
android:text="Şikayet Grafiği"
android:textColor="#color/white"
android:textSize="#dimen/dp18" />
Is there any special way to show these characters with same font? Or the solution is to stop dealing with this and use different font ?
check this post for setting special characters in xml file and this if you want to set using java language
I need to show SmallCaps text in TextView. I am trying to use code below:
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFeatureSettings="smcp"
android:textColor="#color/black"
android:textSize="16sp"
android:text="TEXT" />
But it just shows me normal text, without SmallCaps effect. I also try to set it programmatically (text1.fontFeatureSettings = "smcp") but also without success.
How to make SmallCaps text in Android? Why fontFeatureSettings doesn't work?
In order for this feature to work you have to have a font that actually has Small Caps characters - thus to make it work pass the font with Small Caps via app:fontFamily(android:fontFamily) for example Aller Display, and then use android:fontFeatureSettings="smcp" to make it Small Caps.
Hope it helps
Edit
as #Cliabhach pointed in comments, in code it will look something like
text1.typeface = resources.getFont(R.font.Aller_Display)
text1.fontFeatureSettings = "smcp"
Edit2
Keep in mind
For those who do not know - Small Caps will only work on lowercase characters
As you are using TextView so I guess you set value to it at runtime like says you have some String object which will get set to the TextView like:
textView.setText(someStringObj);
So you can easily set it as in lower case on it by adding:
textView.setText(someStringObj.toLowerCase());
I'm really confusing how the android's design/front-end works. A lot of questions are in my mind that, why android not provider easy way/method ( as in html like border-bottom, or in JavaFX) to add borders in textview or something other blah blah. but afraid may be stackoverflow not allowed me ask such question. One question of them which I want to ask here is that what is required to use android:backgroundTint
Because in the EditText it is working as simple.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edting"
android:backgroundTint="#00FFFF"
/>
but in the TextView to work with it or to add the border I have to use a drawable utility.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edting"
android:backgroundTint="#00FFFF" // not working at all
/>
Somewhere I read that it add the shade to background. But why it is changing the bottom-border. So another question could be the actual purpose of android:backgroundTint
I'm a newbie to Android and I have looked at similar questions asked by others without a definite answer, since, I think, my problem is a bit different.
I'm using a TextView in my program in which there can be links, text, numbers etc. following is the TextView I'm using.
<TextView
android:id="#+id/viewText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:autoLink="web"
android:linksClickable="false"
android:ellipsize="end"
android:maxLines="7" />
Although this is working for normal texts, the ellipsize does not work whenever links are present in the TextView. I'm using "autoLink" in order to show the user that it is link but had set android:linksClickable to false. Right now, I've added the ellipsize from the code but I want to know whether I can do it from the XML file itself.
Thank you.