Package Com.dute.dutenews.utils;import Android.app.activity;import Android.content.context;import Android.view.view;import Android.view.windowmanager;import Android.view.inputmethod.inputmethodmanager;public Class ToolWindow {/** * Sets the background transparency of the add screen * * */public static void Setbackgroundalpha (Activity contex T, float Bgalpha) {windowmanager.layoutparams LP = Context.getwindow (). GetAttributes (); Lp.alpha = Bgalpha; 0.0-1.0 Context.getwindow (). SetAttributes (LP); }/* * Hide Soft keyboard */public static void Hidesoftinputfromwindow (context context, view view) {//1. Get input Methodmanager object Inputmethodmanager IMM = (inputmethodmanager) context. Getsystemservice (Context.inpu T_method_service); 2. Call the Hidesoftinputfromwindow method to hide the soft keyboard Imm.hidesoftinputfromwindow (View.getwindowtoken (), 0); Force Hide Keyboard}/** * Display soft Keyboard * * @param context * @param view */public static void ShowsoftInput (Context context, view view) {//1. Get Inputmethodmanager object Inputmethodmanager IMM = (inputmethodmanager ) context. Getsystemservice (Context.input_method_service); 2. Call the Showsoftinput method to display the soft keyboard, where view is the focused view component Imm.showsoftinput (view, inputmethodmanager.show_forced); /** * To toggle display of the soft keyboard function * * @param context * @param view */public static void Togglesoftinpu T (context context) {///1. Get Inputmethodmanager object Inputmethodmanager IMM = (inputmethodmanager) Context . Getsystemservice (Context.input_method_service); 2. Realize the function of switching display soft keyboard imm.togglesoftinput (0, inputmethodmanager.hide_not_always); /** * Returns true to indicate that the input method is open * */public static Boolean isActive (context context) {//1. Get Inputmeth Odmanager object Inputmethodmanager IMM = (inputmethodmanager) context. Getsystemservice (Context.input_me Thod_service); Return imm.isactive (); }/** * from the DP unit according to the resolution of the phone to be px (pixels) */public static int dip2px (context context, float dpvalue) {fin Al Float scale = context.getresources (). Getdisplaymetrics (). density; return (int) ((Dpvalue * scale) + 0.5f); }/** * from the PX (pixel) unit to the cell phone's resolution to be DP */public static int Px2dip (context context, float pxvalue) {fin Al Float scale = context.getresources (). Getdisplaymetrics (). density; return (int) ((Pxvalue/scale) + 0.5f); }}
ToolWindow Tool Class