android-edittext

Android Edit text alignment

夙愿已清 提交于 2019-12-04 15:40:14
问题 I am making a small app for a tablet, something like a display sign. I have a few text elements that are center aligned in the display sign. When I tap on it, it gets converted to editText. I want the edit text in such a way that the text in it is center aligned and content wrapped. But when i input something, editText expands both ways, keeping the text aligned to the center. I want to do the same thing with right aligned text elements (only difference is that the edit text would expand only

Having the mandatory symbol to the edit text (red color asterisk) which is inside the textinputlayout

落花浮王杯 提交于 2019-12-04 15:23:01
I have an edit text inside a textinputlayout. I am trying to set the mandatory field symbol (red color asterisk) to the edittext. I have set the hint to the edit text. My code is as below. <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" * " android:layout_gravity="center_vertical" android:textColor="#ff0000" android:textSize="15sp" /> <android.support.design

Configure android EditText to allow decimals and negatives

ⅰ亾dé卋堺 提交于 2019-12-04 15:05:52
问题 I have an Android EditText that I want to have the number keyboard come up. If I set the android:inputType to numberSigned, I get the number keyboard and the ability to type in negatives. However this won't let me use decimals. If I use the numberDecimal inputType I can use decimals but not negatives. How do you get the number keyboard with the ability to type in decimals and negatives? 回答1: You are just missing this in your EditText, android:inputType="numberDecimal|numberSigned" 回答2: We can

Get numbers from EditText

放肆的年华 提交于 2019-12-04 14:52:31
I know that his have been asked a few times, but I have been trying everything I have found with no luck. I'm still having a error. Here's my code. xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:background="@android:color/transparent" android:gravity="center" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=

How to comma-separate numbers in EditText

非 Y 不嫁゛ 提交于 2019-12-04 14:33:56
I have an EditText that has an inputType of number . While the user is typing, I want to comma-separate the numbers. Here's a little illustration: 123 would be represented as 123 1234 would be represented as 1,234 12345 would be represented as 12,345 ...and so on. I tried adding a comma with TextWatcher as shown below: EditText edittext = findViewById(R.id.cashGiven); edittext.addTextChangedListener(new TextWatcher(){ @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2

Android Development: Count EditText Lines on textChanged?

前提是你 提交于 2019-12-04 14:15:20
How can I count the number of lines in an EditText? Basically in my app I have line numbers and I wanted to make them update on textchange (I already have the textchangelistener set up). Is this possible? :( Thanks, Alex! Whiler Lines can be differents: Visible lines: Wrapped text count as a new line... List item: Only lines with \r, \n, \r\n First case (the easiest): int nbLines = editText.getLineCount(); Second case: int nbLines = 0; StringReader sr = new StringReader(editText.getText().toString()); LineNumberReader lnr = new LineNumberReader(sr); try { while (lnr.readLine() != null){}

how to enable vertical scrollbar of an edittext programmatically

好久不见. 提交于 2019-12-04 13:46:49
I'm trying to implement android:scrollbars="vertical" in XML by Java code. I've tried method setVerticalScrollBarEnabled(true) but it doesn't work. Anyone can give me a suggestion? Thanks in advance. you can use EditText ed=new EditText(context); ed.setScroller(new Scroller(context)); ed.setVerticalScrollBarEnabled(true); this will give the scroll option for the edit text but it won't show the scroll bar. 来源: https://stackoverflow.com/questions/8417454/how-to-enable-vertical-scrollbar-of-an-edittext-programmatically

android edittext currency format without dollar symbol

落爺英雄遲暮 提交于 2019-12-04 13:15:30
I try to create currency format in my edittext.i searched and i wound code and i can add currency format in my edittext transfer_maney.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (!s.toString().equals(current)) { transfer_maney.removeTextChangedListener(this); String cleanString = s.toString().replaceAll("[$,.]", ""); double parsed = Double.parseDouble(cleanString); String formatted = NumberFormat

EditText Height Issue

◇◆丶佛笑我妖孽 提交于 2019-12-04 12:52:26
I am trying to set smaller height of EditText but still have not managed it. Here is my source: <EditText android:layout_width="150dp" android:layout_height="20dp" android:singleLine="true" android:textSize="10dp" /> This code cuts out text and a white rectangular shape appears around EditText control. I have also tried maxHeight/minHeight properties, but did not worked either. If anybody have solved this issue, please help. Or is this is the bug in the android? I can not even resize Spinner, same happens as with EditText. Thanks Irfan You are probably seeing bizarre orange rectangular shapes

How to show space key in softkeyboard and perform some action when user clicks on space key

浪子不回头ぞ 提交于 2019-12-04 12:13:41
I have an edittext. In that edittext user enters some text. when user hits on space key, i need to perform some action. how can i do it. Thanks in advance. jcw To do something when the user presses the space key you use the following - if((event.getAction()==KeyEvent.ACTION_DOWN)&&(key == KeyEvent.KEYCODE_SPACE)){ //put your code for whatever you what to do when the user presses space here } } Problems intercepting space key in EditText If you have multiple edittexts, in the above code put if (edittext.hasFocus()){ //do something for particular edit text } I think I know why your edittext is