Changing position of the Dialog on screen android

I used this code to show the dialog at the bottom of the screen: Dialog dlg = <code to create custom dialog>; Window window = dlg.getWindow(); WindowManager.LayoutParams wlp = window.getAttributes(); wlp.gravity = Gravity.BOTTOM; wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND; window.setAttributes(wlp); This code also prevents android from dimming the background of the dialog, if you need it. You should … Read more

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event

Solution: Override isSuggestionsEnabled and canPaste in EditText. For the quick solution, copy the class below – this class overrides the EditText class, and blocks all events accordingly. For the gritty details, keep reading. The solution lies in preventing PASTE/REPLACE menu from appearing in the show() method of the (non-documented) android.widget.Editor class. Before the menu appears, … Read more

Programmatically update widget from activity/service/receiver

If you are using an AppWidgetProvider, you can update it this way: Intent intent = new Intent(this, MyAppWidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID, // since it seems the onUpdate() is only fired on that: int[] ids = AppWidgetManager.getInstance(getApplication()) .getAppWidgetI‌​ds(new ComponentName(getApplication(), MyAppWidgetProvider.class)); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); sendBroadcast(intent);

Highlight Text in TextView or WebView

enable TextView’s Spannable storage! by default Spannable storage in EditText is true. so TextView myTV = (TextView)findViewById(R.id.textView1); String textString = “StackOverFlow Rocks!!!”; Spannable spanText = Spannable.Factory.getInstance().newSpannable(textString); spanText.setSpan(new BackgroundColorSpan(0xFFFFFF00), 14, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); myTV.setText(spanText);

Clickable widgets in android

First, add a static variable with a constant. public static String YOUR_AWESOME_ACTION = “YourAwesomeAction”; Then you need to add the action to the intent before you add the intent to the pending intent: Intent intent = new Intent(context, widget.class); intent.setAction(YOUR_AWESOME_ACTION); (Where widget.class is the class of your AppWidgetProvider, your current class) You then need to … Read more