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"
Related
One of the users of my app is having an issue where the text he enters in the EditText elements of my app is white, which effectively renders it invisible against a white background. He's the only user experiencing this issue, and it's only happening to him in my app.
As an example, here's the code for one of my EditText elements:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/usernameTextBox"
android:imeOptions="actionDone"
android:singleLine="true"/>
There are dozens of these in my app, and all are essentially coded the same. Any ideas why this might be happening?
Every android distribution can overwrite default colors for widget. Therefore, if you want all of your EditText to look the same you should explicitly set their background and text color like so:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/usernameTextBox"
android:imeOptions="actionDone"
android:singleLine="true"
android:background="#FFFFFF"
android:textColor="#000000"/>
To ensure that the text colour being displayed correctly, strictly set the textColor attribute for each declared TextView like so android:textColor="#android:color/black"
I have this EditText
<EditText
android:layout_width="match_parent"
android:layout_height="72dp"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textImeMultiLine"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
When the box is filled up with user inputted text, it scrolls to the right to make room for more text, I do not like this behavior, and would prefer it if the EditText box expanded upwards when it needs more room? Is there a way to do this? Thanks.
Yes, this actually involves two things:
Making the EditText accept multi-line input.
Having its height grow as more text lines are added.
Therefore, to achieve this, you need to set up:
android:inputType="textMultiLine"
android:layout_height="wrap_content"
(Be mindful of the difference between textMultiLine and textImeMultiLine).
The full XML snippet would be:
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
Use both flags: textMultiLine will wrap your input, and textImeMultiLine will provide a break-line key in your keyboard.
<EditText
...
android:layout_height="wrap_content"
android:inputType="textImeMultiLine|textMultiLine"
... />
In my case I have multiline text, but it showed one line and a keyboard:
Though I have already set android:inputType="textCapSentences|textAutoCorrect|textMultiLine", it didn't help. Then I understood that when the keyboard appears in DialogFragment, it collapses the EditText. See DialogFragment and force to show keyboard to show keyboard when DialogFragment shows.
Then I added a short delay (100-300 ms) before showing the keyboard. Now I have:
In AndroidManifest I set android:windowSoftInputMode="adjustResize" for current activity.
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"*
I have a very simple layout made of TextViews and disabled EditTexts put by turns. Most of the EditTexts contain plain text but I have two special fields and I have problem with them:
Phone number: as an autoLink type I set "phone". The problem is that a phone number is invisible until I click inside the edit:
<EditText
android:id="#+id/service_order_contact_phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:focusable="false"
android:enabled="false"
android:inputType="phone"
android:gravity="right"
android:autoLink="phone" >
</EditText>
I would like to enable user to click address to open google map. I set an autoLink attribute to "map" but it seems not to work. Do you know how to do it?
<EditText
android:id="#+id/service_order_address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:enabled="false"
android:focusable="false"
android:singleLine="false"
android:lines="2"
android:inputType="textPostalAddress|textMultiLine"
android:autoLink="map"
android:gravity="right" >
</EditText>
I don't think EditText and autoLink are designed to work together... Think about this scenario when the user is editing a value:
The user enters a phone number, say: 5557891234
The user made a mistake and clicks in the middle of the EditText to be able to change a digit in the middle of the phone number...
Instead of being allowed to edit the number, the link action takes them to the dialer with the incorrect phone number.
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