In edittext hint need to scroll horizontally - android

In my app i have Edit text with fixed size but hint size is more than edit text so hint is not displayed fully.I want to display hint fully by scrolling horizontally but i don't have any idea how to do this.
If reduce the size of hint font it will help but i don't want to reduce font size.
Following is the example code which i use.
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="true"
android:id="#+id/test_etx"
android:hint="#string/hint"
android:layout_below="#+id/bt3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="29dp"
android:layout_alignRight="#+id/etx"
android:layout_alignEnd="#+id/etx"
android:maxLength="10"
/>

Make your EditText width match_parent. Put that inside a horizontal scroll view. I tried and it works. If you want fixed width, give fixed width to your horizontal scroll view. Like this :
<HorizontalScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bt3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="29dp"
android:layout_alignRight="#+id/etx"
android:layout_alignEnd="#+id/etx">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="true"
android:id="#+id/test_etx"
android:hint="#string/hint"
android:maxLength="10"/>
</HorizontalScrollView>

First you can add a scroll in editText then put text in edit Text with grey font color instead of hint and then put a OnClickListener on the editText. If input text matches hint then set it to "" else process the data.
Make two arrays of EditText id and its corresponding hint in values res. Then fetch both arrays using getResource().
Use
String str = view.getResources().getResourceName(id);
str = str.substring(str.lastIndexOf(":id/") + 4);
to get view id.
match hint from stored array's hint to input text. I think it will be generalised for all the layouts. Hope it helped.

Related

Display non-editable text at end of EditText in android

I want to display text at the end of EditText as shown in the image above for URLName.How could I acheive this ?The text cannot be edited.I am using this editText inside TextInputLayout from the design library. thanks in advance
Create a LinearLayout. An example of a row inside this layout would be a title (i.e. URL name) or a text entry field.
Set the background of the LinearLayout for the current row to a custom drawable to create a thin red line. Follow the answers on this post for ideas.
For the URL entry field mentioned in your question, create a TextView and an EditText inside another LinearLayout inside the current row.
The TextView will contain ".sitename.com". Set it to wrap_content and give it a weight of 0. For your EditText, set its width to 0dp and its weight to 1. It should now fill all remaining space. Set the background to #null for both.
This worked for me :
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_alignParentLeft="true"
android:id="#+id/youeeditid"
android:layout_gravity="center"
/>
<TextView
android:id="#+id/text_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="HintText"
android:textSize="18sp"
android:layout_marginRight="10dp"
android:textColor="#808080"
/>
</RelativeLayout>
It's little bit tricky but it's works for me.
BUT
If you want to set only EditText then you can do below :
1) Set Gravity of EditText to "Right" and Ellipsize to "End" .
2) Now In onCreate() method write onclicklistener of EditText and set
Gravity as "Left".
3) Or you can also set programatically on OnKeyListener , where check
if lenght of edittext is equal to Zero set EditText's gravity as
Left.
Reference : Setting cursor to the right on an EditText with HINT Gravity to center

Ellipsize within word possible?

I have a list of items where the words may be longer then the width of the textView. I would like the text to be ellipsized.
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="* SomeVeryLongWordWhichIsLongerThanWidth" />
The problem is, that the output is *... instead of * SomeVeryLongWordWhi.... How can I achieve the latter?
You could use \u00A0 instead of normal space sign
\u00A0 its non-breakable space
android:text="*\u00A0SomeVeryLongWordWhichIsLongerThanWidth"

Android RelativeLayout editview how to make a text box bigger?

I'm trying to make a text box about 3 lines high but also the textbox will also expand depending on the amount of information entered. I've used wrap_content which displays as one line and I've used android:layout_height="150dp", however the text box does not expand. Any guidance would be much appreciated.
<EditText
android:id="#+id/editEmailCompose"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/editEmailSubject"
android:layout_toRightOf="#+id/textSubject"
android:ems="10"
android:gravity="top|left"
android:layout_marginRight="20dp"
android:hint="#string/emailCompose" />
Ok so I found the code required. It may help others.
*android:layout_height="wrap_content"
android:isScrollContainer="true"
android:minHeight="120dp"
android:inputType="textMultiLine"*

Padding for hint text inside EditText

I want to be able to add padding to the text that is displayed inside the EditText, using
android:hint="some text"
If I only add padding for the EditText regularly, it adds the padding for the whole view. And i want it for the text that gives a hint for the user, what needs to be entered. If someone knows how to do this, please give me a feedback.
You may find your solution in this answer:
EditText set text start 10dp from left border
It helped me to achieve the padding for hint in username field:
<EditText
android:id="#+id/txtUsername"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:background="#drawable/bkg_login_txt_usuario"
android:hint="#string/hint_username"
android:paddingLeft="10dp"
android:singleLine="true" >
<requestFocus />
</EditText>
I hope this helps.
You can use android:drawablePadding which denotes the padding between the drawable and the hint texts.
Use the TextChangedListener and a TextWatcher to monitor the text inside the EditText. Use the TextWatcher check to see if the EditText is empty and set the padding, otherwise remove the padding.

Android EditText problems

i have created an EditText like this
<RelativeLayout>
<TableLayout>
<TableRow>
<EditText android:id="#+id/myid"
android:hint="This is my hint"
android:textColorHint = "#color/white"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:textSize = "20sp"
android:textColor = "#color/white"
android:textStyle = "bold"
android:background ="#drawable/mybackgroundimage"
android:fitsSystemWindows = "true"
android:includeFontPadding = "true"
android:singleLine="true"
android:cursorVisible = "false"
>
</EditText>
</TableRow>
</TableLayout>
Its in a table layout. i have 2 problems
As soon as i remove android:gravity="center" hints shows but i need to show text from centre and show hints in edit text as well(Is it a bug in android sdk?).
i like to wrap text up-to a certain size if texts grows larger than textview bounds.Right now it goes beyond the view and doest not shows the entered digits after its ending but digits keeps on getting added in edit text.
Please if anyone have any idea how to do this.
Thanks
To show all the text in the EditText just add:
android:scrollHorizontally="true"
As soon as i remove android:gravity="center" hints shows but i need to
show text from centre and show hints in edit text as well(Is it a bug
in android sdk?).
I don't understand what you mean at the fist point. Can you explain it to me?
(if i understand the question)android:gravity="center" allways refear to the "son" of the view. the "son" of the EditText is the text. If you want to put the EditText in the center and the text in the center you should put other gravity=center in the tablerow.
You should change the size of the text programatically:
if (myid.getText().toString().lengh()> XX )
myid.setTextSize("xxdip")
Or something like this

Categories

Resources