switch (attribute.inputType & EditorInfo.TYPE_MASK_CLASS) {
case EditorInfo.TYPE_CLASS_NUMBER:
case EditorInfo.TYPE_CLASS_DATETIME:
case EditorInfo.TYPE_CLASS_PHONE:
mCurKeyboard = mSymbolsKeyboard;
break;
case EditorInfo.TYPE_CLASS_TEXT:
mCurKeyboard = mQwertyKeyboard;
}
这是什么意思?
我的测试结果是:
attribute.inputType = 17
EditorInfo.TYPE_MASK_CLASS = 15
它切换到 case EditorInfo.TYPE_CLASS_TEXT
,即 = 1
最佳答案
二进制...
10001 // 17
01111 // 15
...&
运算符表示您要匹配 bits
,其中两者都是 1
。
按位看起来像这样......
10001 // 17
01111 // 15
-----
00001 // 17 & 15
只有最后一个 bit
两个数字匹配为 1
。
关于android - 用 '&' 切换两个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12343436/