ToolWindow Tool Class

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.