杂七杂八 android小工具类

来源:互联网 发布:三星s5网络模式仅限2g 编辑:程序博客网 时间:2024/05/29 18:02

一、关闭软件盘

    public void closeInput() {        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);        if (inputMethodManager != null && HelpActivity.this.getCurrentFocus() != null) {            inputMethodManager.hideSoftInputFromWindow(HelpActivity.this.getCurrentFocus().getWindowToken(),                    InputMethodManager.HIDE_NOT_ALWAYS);        }    }

二、检测版本号

android.os.Build.VERSION.SDK_INT < 18

三、是否支持蓝牙

 BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);            mBluetoothAdapter = bluetoothManager.getAdapter();            if (mBluetoothAdapter == null) {}

四、是否有连接网络

  ConnectivityManager cwjManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);        NetworkInfo info = cwjManager.getActiveNetworkInfo();        if (info != null && info.isAvailable()) {            return true;        }        else {            return false;        }

五、小线程

 new Thread(new Runnable() {            @Override            public void run() {                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);                if (inputMethodManager != null && PkiHardWareActivity.this.getCurrentFocus() != null) {                    inputMethodManager.hideSoftInputFromWindow(PkiHardWareActivity.this.getCurrentFocus()                            .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);                }            }        }).start();


六、textview 文本复制

                // TODO Auto-generated method stub                ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);                final String temp = textView1.getText().toString();                cmb.setText(temp.toString());                Toast.makeText(context, "Copy success", Toast.LENGTH_SHORT).show();                Vibrator vibrator;                vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);                long[] pattern = { 100, 100, 0, 0 };                vibrator.vibrate(pattern, -1);                return false;            

七、动态布局

tv_left.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));        RelativeLayout.LayoutParams lp = (LayoutParams) tv_left.getLayoutParams();        lp.addRule(CENTER_VERTICAL);        tv_left.setLayoutParams(lp);




0 0
原创粉丝点击