Created
October 28, 2014 14:32
-
-
Save ishitcno1/89ff4f671a952f3b0ccd to your computer and use it in GitHub Desktop.
android widget utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WidgetUtils { | |
/** | |
* create alert dialog | |
* | |
* @param context | |
* @param layout | |
* @param showSoftInput | |
* @return | |
*/ | |
public static AlertDialog createAlertDialog(Context context, int layout, boolean showSoftInput) { | |
AlertDialog dialog = new AlertDialog.Builder(context).create(); | |
dialog.show(); | |
dialog.setContentView(layout); | |
Window window = dialog.getWindow(); | |
if (showSoftInput) { | |
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); | |
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); | |
} | |
WindowManager.LayoutParams lp = window.getAttributes(); | |
lp.width = WindowManager.LayoutParams.MATCH_PARENT; | |
lp.height = WindowManager.LayoutParams.WRAP_CONTENT; | |
lp.gravity = Gravity.BOTTOM; | |
window.setAttributes(lp); | |
return dialog; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment