Problem with ellipsesize - android

I have a TextView I use to display email addresses to my users
<TextView
android:id="#+id/profile_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip"
android:textColor="#000000"
android:maxLines="1"
android:ellipsize="end" />
My issue is that many email addresses get cut off in the middle instead of having an ellipse at the end. Here is an example:
If my email address is
short.name#mydomain.com
everything works fine. However, If my email address is
really.longfreakennameforanemailaddressandscreenisntwideenough#mydomain.com
the only thing that will display is
really.
Any ideas?

As a workaround you can use :
android:scrollHorizontally="true"

Related

Android cannot deselect TextView

I'm making a simple test app to wrap my head around reading text from TextViews in android.
My problem is: I have 2 TextViews, one for a username and one for a password field, and a button. The button calls a method that gets text from both TextViews. However, my username TextView is automatically selected when the app runs and I can type text into it, and I cannot deselect it and select the password field to write into, but I can click the button. Does anybody know what the issue might be?
Android 7.0 used for testing
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/userField"
android:layout_width="#dimen/textView_width"
android:layout_height="#dimen/textView_height"
android:layout_above="#id/passField"
android:layout_marginHorizontal="#dimen/activity_horizontal_margin"
android:layout_marginVertical="#dimen/activity_vertical_margin"
android:background="#color/LightCoral"
android:gravity="center_vertical"
android:hint="#string/user"
android:inputType="text"
android:textAlignment="gravity"
android:textSize="10pt"
android:visibility="visible" />
<TextView
android:id="#+id/passField"
android:layout_width="#dimen/textView_width"
android:layout_height="#dimen/textView_height"
android:layout_centerInParent="true"
android:layout_marginHorizontal="#dimen/activity_horizontal_margin"
android:layout_marginVertical="#dimen/activity_vertical_margin"
android:background="#color/LightCoral"
android:gravity="center_vertical"
android:hint="#string/pass"
android:inputType="textPassword"
android:textAlignment="gravity"
android:textSize="10pt"
android:visibility="visible" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/passField"
android:layout_centerHorizontal="true"
android:width="#dimen/button_width"
android:height="#dimen/button_height"
android:background="#color/FireBrick"
android:onClick="uradi"
android:text="#string/button_tag"
android:textColor="#color/Black" />
</RelativeLayout>
EditText is better widget over TextView for handling user input. Replace your TextView with EditText
You should choose the controls that are suitable for the use of the sense.
The input of the username and password is generally used for EditText

Why can't I show the excess characters entered in a textview?

I want the textview to show excess characters entered and push the old ones left as in any standard calculator app where the latest character entered is visible. The maxLength = 14. When characters are typed (once 14 characters are entered as in the image) then it doesn't show them at all. I think I am doing something wrong but can't figure it out what. I have read other answers on stackoverflow for some similar errors and tried the solutions but it didn't work.
Thanks :)
Here's the xml Code for the textview:
`
<TextView
android:id="#+id/full_expression"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_weight="1"
android:alpha="0.85"
android:background="#android:color/transparent"
android:elevation="6dp"
android:fontFamily="sans-serif"
android:gravity="bottom|end"
android:maxLength="14"
android:maxLines="1"
android:paddingEnd="10dp"
android:scrollHorizontally="true"
android:text="0"
android:textColor="#android:color/background_light"
android:textSize="34sp" />
Use "android:gravity" property to align your text inside textview.

Hint and Text in editText at same time

I just need an editText in which i can set Text and hint at the same time.
e.g i want user to enter in editText string like user#1234
in this string user# should be text after that numbers will vary so that 1234 should be show as hint when user try to enter cursor will go after # and 1234 hint will gone when user type a character.
Please guide me how to do this.
Thanks
I managed to achieved this with bit of tricks and playing with margin and padding
This is what I did
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp" >
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="user#" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="1234"
android:paddingLeft="40dp"
android:textSize="14sp" />
</RelativeLayout>
Hope this will help you out
This is not possible in the Android's default EditText but if want to achieve this any how, you will have to work a bit.
You can use this library called Masked-EditText. Read the documentation and understand how you can use it to solve your purpose. Hope that helps.
[EDIT]
I've got one more trick that you can definitely use. Implement an onChangeListener on the edit text. Every time it is called, run a function. The function should get the text in the editText and get the substring (first 5 char). If the substring matches "user#" then do not do anything. Else replace the text in editText with "user#". Easy hah!
You can do this in 2 ways
#1
Place an Image with user# as drawableLeft to your EditText
#2
Use a RelativeLayout to place a TextView and EditText one above the other so that it shows text in TextView as hint in EditText as below :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_parent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="user#"
android:textColor="#aaaaaaaa"
android:textSize="30dip" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_toRightOf="#+id/textView1"
android:background="#00000000"
android:textSize="30dip">
</EditText>

Is there a workaround for the hint bug?

So I'm currently facing a bug on android, where if I set, for an EditText, a gravity to "center", an inputType and a hint, the hint is not displayed. I've tried multiple advices, like adding `singleLine="true", an ellipsize parameter, or a few others, with multiple combinations of these, but to no effect. I can only manage to get either my field not centered with a hint, or centered but without a hint.
The trade-off I currently use (no inputType):
<EditText
android:id="#+id/view_email"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="12dp"
android:layout_weight="1"
android:paddingTop="7dp"
android:paddingBottom="7dp"
android:gravity="center"
android:maxLines="1"
android:ellipsize="start"
android:hint="#string/email_placeholder"
android:background="#ffffff"
android:imeOptions="flagNoExtractUi"/>
Apparently it's a known bug, but I couldn't find any workaround that actually worked in my case. I just try to have an EditText for an input of type "email", with a centered hint.
Has anyone come with a workaround that actually works for this? I found out that it's quite a PITA for users to enter an email when the input type is not set to email.
This worked for me, give it a try
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:digits="0123456789.,"
android:ellipsize="start"
android:maxLines="1"
android:gravity="center"
android:background="#ffffff"
android:hint="#string/email_placeholder">
</EditText>
perhaps you could use this as a workaround: https://github.com/malmstein/FloatingHints
<EditText
android:id="#+id/view_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_weight="1"
android:paddingTop="7dp"
android:paddingBottom="7dp"
android:gravity="center"
android:maxLines="1"
android:ellipsize="start"
android:hint="#string/email_placeholder"
android:background="#ffffff"
android:imeOptions="flagNoExtractUi"/>
This works for me. just changed the height attribute

Linkify properly an email address with subject

I want to linkify a email address and put a static subject to the email.
In the layout I have this:
<TextView
android:id="#+id/textView5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:autoLink="email"
android:text="#string/email" />
How can I add the subject to the email? I should do this in the Activity with the addLinks() method, am I right? I tried some combinations but the email was being appended to the subject...
I checked those sources but without luck:
Email from a link and Android Intents - bring it home
Android Text Links Using Linkify
Linkify your Text!
I found a solution:
<TextView
android:id="#+id/textView5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:clickable="true"/>
TextView mailTV = (TextView) findViewById(R.id.textView5);
mailTV.setText(Html.fromHtml("<a href=\"mailto:"+getString(R.string.email)+"?subject="+getString(R.string.email_subject)+"\" >"+getString(R.string.email)+"</a>"));
mailTV.setMovementMethod(LinkMovementMethod.getInstance());

Categories

Resources