ToolWindow tool class, popupwindow tool class

Source: Internet
Author: User

ToolWindow tool class, popupwindow tool class

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 screen to be added. ***/public static void setBackgroundAlpha (Activity context, float bgAlpha) {WindowManager. layoutParams lp = context. getWindow (). getAttributes (); lp. alpha = bgAlpha; // 0.0-1.0 context. getWindow (). setAttributes (lp);}/** hide keypad */public static void hideSoftInputFromWindow (Context context, View view) {// 1. obtain the InputMethodManager object InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE); // 2. call hideSoftInputFromWindow to hide the keyboard imm. hideSoftInputFromWindow (view. getWindowToken (), 0); // force hide the keyboard}/*** display the soft keyboard ** @ param context * @ param view */public static void showSoftInput (Context context, view view) {// 1. obtain the InputMethodManager object InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE); // 2. call the showSoftInput method to display the keyboard, where view is the focused view component imm. showSoftInput (view, InputMethodManager. SHOW_FORCED);}/*** implement the function of switching to display the soft keyboard ** @ param context * @ param view */public static void toggleSoftInput (Context context) {// 1. obtain the InputMethodManager object InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE); // 2. implement the function of switching to display the keyboard imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS);}/*** if true is returned, the input method is enabled. **/public static boolean isActive (Context context) {// 1. obtain the InputMethodManager object InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE); return imm. isActive ();}/*** convert the unit from dp to px (pixel) */public static int dip2px (Context context, float dpValue) based on the cell phone resolution) {final float scale = context. getResources (). getDisplayMetrics (). density; return (int) (dpValue * scale) + 0.5f);}/*** based on the resolution of the phone) to dp */public static int px2dip (Context context, float pxValue) {final float scale = context. getResources (). getDisplayMetrics (). density; return (int) (pxValue/scale) + 0.5f );}}

 

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.