In Android where can I set the text that automatically reduce size when is too long ?
Using android:autoText="true" doesn't work.
Add app:autoSizeTextType="uniform" to your Button. Check this link for more details.
Try to use:
android:ellipsize="end"
It will add 3 dots at the end of the text if it's too long.
use android:ellipsize="end" property when the text is longer than the size of the button
<Button android:text="Button"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:ellipsize="end">
</Button>
From android developer page it says This class accesses a dictionary of corrections to frequent misspellings, as well as this page it says If set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors. The default is "false".
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form "#[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol autoText., so android:autoText="true" is not for adjusting the text size but it is something related to spell correction.
From what i understand about your problem, you are looking for a solution through which text is fully displayed on button and never truncated. If text is longer than button size, textsize should be reduced to fit in the text within the button bounds.
So there is one post related to autosize but it is related to Textview.
So you can use this as starting point and build your solution.
Related
I have declared in my fragment a textInputLayout which contains an edit text with parameters
android:inputType="textCapCharacters"
android:maxLength="3"
android:maxLines="1"
and it works correctly on most devices, it "survives" while user is trying to input more than 3 characters, but IF user tries to paste a string, which contains more than 3 characters it ends up crashing.
"java.lang.IndexOutOfBoundsException: setSpan (0 ... 10) ends beyond length 3"
and just to be clear, the app doesn't crash after pasting longer strings on most of the devices but on some it does, and thus is why I'm here, is there any way I could prevent that?
You Could use the CLIPBOARD_SERVICE on your fragment as stated here , enable the editing (only if it's plain text), finally do a string.take(3) and assign that to your text property on the textInputLayout.
Please refer this question.
(When setting the Edit cursor, when measuring the Edit content length, it is 0, that is, the measured content is not found.)
How i can use little letters in buttons title?
I'm creating string in res/values/strings.xml with register, but still getting Caps.
You could add android:textAllCaps="false" to the button.
The button text might be transformed to uppercase by your app's theme that applies to all buttons. Check themes/styles files for setting the attribute android:textAllCaps.
Accroding to this link
I'm using the new TextInputLayout provided by Android.support to do floating label. But it will fail Espresso Accessibility Check because "View is missing speakable text needed for a screen reader".
Looked into it and find out the TextInputLayout will nullify hint when parent does addView(). This is basically how it can float the label up(set the label, nullify the hint). And any EditText with null hint will fail the accessibility check.
Anyone knows how to resolve this issue? It's really driving me crazy..
Thanks a lot!!!!
A great way to make TextInputLayout accessible is to use "LabelFor" as recommanded by ChrisCM, but you don't have to add an invisible label view to do so: Just put the labelFor or your Textinputlayout and make it point to your EditText
Example:
<android.support.design.widget.TextInputLayout
android:labelFor="#+id/username"
android:contentDescription="#string/username_hint"
android:accessibilityLiveRegion="polite">
<edittext
android:id="#+id/username"
android:hint="#string/username_hint"
…/>
</android.support.design.widget.TextInputLayout>
This way you get the exact same visual behaviour and make "Espresso Accessibility Check" and Talkback happy :)
(To make TextInputLayout fully accessible I also added android:accessibilityliveregion on the TextInputLayout element to trigger talkback whenever the error is poping)
A big thanks to this post this blog post which helped a lot
Hints aren't great for accessibility in general. They disappear when text is entered. Try using a "LabelFor" instead. If you don't want a visible label, you can set your label to not be displayed.
This app will give you hints on how to make text boxes accessible.
https://play.google.com/store/apps/details?id=com.dequesystems.accessibility101
Alternatively, if this is a false positive you can ignore checks as described here
val validator: AccessibilityValidator = AccessibilityChecks.enable().apply {
setSuppressingResultMatcher(
allOf(
matchesCheckNames(`is`("TouchTargetSizeViewCheck")),
matchesViews(withId(R.id.my_overflow))
)
)}
The following rules are invoked when we enable tests for accessibility checks:
TouchTargetSizeViewCheck Target height or target width less than 48
dp is flagged, unless there is a touchdelegate detected.
TextContrastViewCheck Checks text color and background and factors in
large text, and calculates the contrast ratio: - 4.5 for regular
text, 3 for large text.
DuplicateSpeakableTextViewHierarchyCheck If
two Views in a hierarchy have the same speakable text, that could be
confusing for users if at least one of them is clickable.
SpeakableTextPresentViewCheck If the view is focusable, this checks
whether valid speakable text exists, and errors if the view is
missing speakable text needed for a screen reader.
EditableContentDescViewCheck Throws an error if Editable TextView has
a contentDescription.
ClickableSpanViewCheck Checks if ClickableSpan
is inaccessible. Individual spans cannot be selected independently in
a single TextView, and accessibility services are unable to call
ClickableSpan#onClick.
RedundantContentDescViewCheck Accessibility
services are aware of the view's type and can use that information as
needed. For example, it throws a warning if the content description
has a redundant word, such as “button.”
DuplicateClickableBoundsViewCheck Throws an error if Clickable view
has the same bounds as another clickable view (likely a descendent).
Sometimes there are containers marked clickable, and they don't
process any click events.
You can make a TextView that has
android:text="My Announcement For Edit Text"
android:labelFor="#id/my_edit_text".
Visibility = gone and visibility = invisible will make it so this label is not announced. Also if you set height and width to 0dp, this will not announce. Instead, constrain the view to be off the screen using something like:
app:layout_constraintEnd_toStartOf="parent"
So your textview will look like this:
<TextView
android:id="#+id/edit_text_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="#+id/my_edit_text"
android:text="Label For My Edit Text"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
This worked for me using withClassName for a view
AccessibilityChecks.enable().setSuppressingResultMatcher(
AccessibilityCheckResultUtils.matchesViews(
Matchers.anyOf(
ViewMatchers.withResourceName("textview1"),
ViewMatchers.withResourceName("button1"),
ViewMatchers.withClassName(Matchers.endsWith("TextInputLayout"))
)
)
)
The length of hint in my EditText is bit longer than the width of ET view. So how can i set marquee attribute to ET view. I have tried setting it, but the app crashes giving the error : E/AndroidRuntime(2095): Caused by: java.lang.IllegalArgumentException: EditText cannot use the ellipsize mode TextUtils.TruncateAt.MARQUEE
I have gone through the docs of ellipsize method, but not getting what i am supposed to do.I have tried these two steps :
1)
android:maxLines="1"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
2) android:maxLines="1"
android:scrollHorizontally="true"
Docs of ellipsize method:
Causes words in the text that are longer than the view is wide to be ellipsized instead of broken in the middle. You may also want to setSingleLine() or setHorizontallyScrolling(boolean) to constrain the text to a single line. Use null to turn off ellipsizing. If setMaxLines(int) has been used to set two or more lines, only END and MARQUEE are supported (other ellipsizing types will not do anything).
Let me know what modification has to be done so that it works right.Thank you
I think marquee doesn't works for EditText.You can use other attribute to ellipsize hint if it is getting longer than the size of editText.
android:ellipsize="end"
#DJphy - I found a solution no need to set ellipsis. when you are setting the string to edit text just set simple HTML attributes to string.
Played with some HTML tricks and it worked for me.
ex:-
nameEdittxt.setHint(Html.fromHtml("<small><small><small>" + getString(R.string.enter_name) + "</small></small></small>"));
This will help to set hint smaller and Edit text size as normal you had set as fontsize.
Look at my attachments -
Before setting HTML attributes to hint -
After setting HTML attributes to hint -
I have a styled TextView whose real text is populated dynamically at runtime. The Graphical Layout view is very useful for getting a feel on how this component works with others in terms of look and feel, etc. There is no sensible default to this text field and I wish it to be blank before being populated. If I don't specify any text in the TextView declaration then the TextView is blank. I can set the text manually using:
<TextView
...
android:text="Preview text"/>
and then switch to the Graphical Layout. However, I must remember to remove this or risk it being shipped in my production version.
Is there a way to specify text which is only seen in the Graphical Layout preview but not applicable at runtime?
EDIT: I'm using Eclipse ADT.
Yes you can with the design tools extension attributes in Android Studio.
See this page https://developer.android.com/studio/write/tool-attributes.html
Basically you define the tools namespace
xmlns:tools="http://schemas.android.com/tools"
Then use it to set your placeholder text.
<EditText
tools:text="John Doe"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
This actually works with most (if not all xml attributes).
e.g
tools:visibility="gone"
would set the preview visibility to "gone" but the runtime visibility would be unchanged.
I don't believe there is, the only possible way is when you declare your TextView, you say after, tv.setText(""); this way you will always find it blank at runtime