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
Related
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.
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
I've got an EditText with my own style. Basically it's a border for the EditText. The problem is that the text starts over this border so it's not very nice. Is there a way of set the starting point of the text in an EditText?
give padding at starting side in layout like this
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
...
android:paddingLeft="10dp"
/>
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.
hi i want to create a control for my activty which is just like an android default dialpad number showing control. i created edittext control for it.
<EditText android:id="#+id/editid"
android:hint="Enter your number"
android:layout_width="fill_parent"
android:scaleType="center"
android:singleLine="true"
android:cursorVisible = "false"
android:layout_height="wrap_content"
>
</EditText>
But its not looking great as i am trying to show the inpput number from centre and keep on decreasing its text size if there are more numbers entered upto a certain size.Also i am unable to set its background drawable to make it look like dialpad's input box.
i also tried with button control.
<Button android:layout_height="45dp"
android:textSize = "25dp"
android:singleLine = "true"
android:id="#+id/input_number"
android:textColor = "#color/white"
android:layout_width="320dp"
android:background="#drawable/num_button">
</Button>
its showing exactly as i want but the problem is now i am not been able to set its text from qwerty keypad as edit text was taking it automatically.
Please someone suggest me which control to choose and get the desired behaviour.
Thanks
Set the gravity of Editext as center and it will work
android:gravity="center"