ratingbar嵌套在alertdialog的坑

通过new ratingbar的形式创建的对话框,虽然也能显示,但是不能精确控制星星的数量,需要把它在xml里定义,然后再inflate进来。

    View ratingBar = getLayoutInflater().inflate(R.layout.dialog_rate,null);

    new AlertDialog.Builder(this).setTitle("温馨提示").setMessage("你对这单如何评价?")
            .setView(ratingBar,16,0,16,0)
            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //TODO ...

                }
            }).setNegativeButton("取消", null).show();

mac下加adb环境变量

1、终端中输入 cd ~ 回车
2、输入 touch .bash_profile 回车
touch:如果没有,则创建文件;如果有,更新一下文件时间
3、输入open -e .bash_profile 回车
open:打开文件
4、在打开的文件最后加入以下内容:
export PATH=/Users/wangduo/Library/Android/sdk/platform-tools/:${PATH}
5、终端中输入 source .bash_profile

蓝牙不需要用户确认的配对方式

        registerReceiver(blePairBroadcastReceiver, IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST))




class BlePairBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { if (intent?.action == BluetoothDevice.ACTION_PAIRING_REQUEST) { try { val device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE) as BluetoothDevice val pin = intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 1234) //the pin in case you need to accept for an specific pin Log.d("BleActivity", "Start Auto Pairing. PIN = " + intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 1234)) val pinBytes: ByteArray pinBytes = ("" + pin).toByteArray(charset("UTF-8")) device.setPin(pinBytes) //setPairing confirmation if neeeded device.setPairingConfirmation(true) } catch (e: Exception) { Log.e("BleActivity", "Error occurs when trying to auto pair") e.printStackTrace() } } } }

禁用通知栏的下拉动作


import android.app.Activity; import android.content.Context; import android.graphics.PixelFormat; import android.util.Log; import android.view.Gravity; import android.view.MotionEvent; import android.view.ViewGroup; import android.view.WindowManager; public class StatusBarUtil { public static void preventStatusBarExpansion(Context context) { WindowManager manager = ((WindowManager) context.getApplicationContext() .getSystemService(Context.WINDOW_SERVICE)); Activity activity = (Activity)context; WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(); localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; localLayoutParams.gravity = Gravity.TOP; localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| // this is to enable the notification to recieve touch events WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | // Draws over status bar WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; //https://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels int resId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android"); int result = 0; if (resId > 0) { result = activity.getResources().getDimensionPixelSize(resId); } localLayoutParams.height = result; localLayoutParams.format = PixelFormat.TRANSPARENT; customViewGroup view = new customViewGroup(context); manager.addView(view, localLayoutParams); } public static class customViewGroup extends ViewGroup { public customViewGroup(Context context) { super(context); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.v("customViewGroup", "**********Intercepted"); return true; } } }