Contact Bubble EditText

Thanks @chrish for all the help. So here is how i did it: final SpannableStringBuilder sb = new SpannableStringBuilder(); TextView tv = createContactTextView(contactName); BitmapDrawable bd = (BitmapDrawable) convertViewToDrawable(tv); bd.setBounds(0, 0, bd.getIntrinsicWidth(),bd.getIntrinsicHeight()); sb.append(contactName + “,”); sb.setSpan(new ImageSpan(bd), sb.length()-(contactName.length()+1), sb.length()-1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); to_input.setText(sb); public TextView createContactTextView(String text){ //creating textview dynamically TextView tv = new TextView(this); tv.setText(text); tv.setTextSize(20); tv.setBackgroundResource(R.drawable.oval); tv.setCompoundDrawablesWithIntrinsicBounds(0, … Read more

How to create EditText with rounded corners?

There is an easier way than the one written by CommonsWare. Just create a drawable resource that specifies the way the EditText will be drawn: <?xml version=”1.0″ encoding=”utf-8″?> <!– res/drawable/rounded_edittext.xml –> <shape xmlns:android=”http://schemas.android.com/apk/res/android” android:shape=”rectangle” android:padding=”10dp”> <solid android:color=”#FFFFFF” /> <corners android:bottomRightRadius=”15dp” android:bottomLeftRadius=”15dp” android:topLeftRadius=”15dp” android:topRightRadius=”15dp” /> </shape> Then, just reference this drawable in your layout: <?xml version=”1.0″ … Read more

Design Android EditText to show error message as described by google

There’s no need to use a third-party library since Google introduced the TextInputLayout as part of the design-support-library. Following a basic example: Layout <android.support.design.widget.TextInputLayout android:id=”@+id/text_input_layout” android:layout_width=”match_parent” android:layout_height=”wrap_content” app:errorEnabled=”true”> <android.support.design.widget.TextInputEditText android:id=”@+id/edit_text” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:hint=”Enter your name” /> </android.support.design.widget.TextInputLayout> Note: By setting app:errorEnabled=”true” as an attribute of the TextInputLayout it won’t change it’s size once an error … Read more

Disable keyboard on EditText

Below code is both for API >= 11 and API < 11. Cursor is still available. /** * Disable soft keyboard from appearing, use in conjunction with android:windowSoftInputMode=”stateAlwaysHidden|adjustNothing” * @param editText */ public static void disableSoftInputFromAppearing(EditText editText) { if (Build.VERSION.SDK_INT >= 11) { editText.setRawInputType(InputType.TYPE_CLASS_TEXT); editText.setTextIsSelectable(true); } else { editText.setRawInputType(InputType.TYPE_NULL); editText.setFocusable(true); } }

Decimal separator comma (‘,’) with numberDecimal inputType in EditText

A workaround (until Google fix this bug) is to use an EditText with android:inputType=”numberDecimal” and android:digits=”0123456789.,”. Then add a TextChangedListener to the EditText with the following afterTextChanged: public void afterTextChanged(Editable s) { double doubleValue = 0; if (s != null) { try { doubleValue = Double.parseDouble(s.toString().replace(‘,’, ‘.’)); } catch (NumberFormatException e) { //Error } } … Read more

Move to another EditText when Soft Keyboard Next is clicked on Android

Focus Handling Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer. Change default behaviour of directional navigation by using following XML attributes: android:nextFocusDown=”@+id/..” android:nextFocusLeft=”@+id/..” android:nextFocusRight=”@+id/..” android:nextFocusUp=”@+id/..” Besides directional navigation you can use tab … Read more