过时修正举例 (Kotlin):
getColor():
resources.getColor(R.color.white) //已过时
// 修正后:
ContextCompat.getColor(this, R.color.white)
getDrawable():
resources.getDrawable(R.mipmap.test) //已过时
//修正后:
ContextCompat.getDrawable(this, R.mipmap.test) //this = Context
setCompoundDrawables(): //未过时但不建议使用
view?.setCompoundDrawables(null,null,null,null) //未过时但不建议使用
//修正后:
view?.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null)
BluetoothAdapter.getDefaultAdapter().isEnabled: //获取蓝牙开关状态
if (!BluetoothAdapter.getDefaultAdapter().isEnabled) { //已过时
//打开蓝牙开关
activity?.startActivity(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE))
}
//修正后:
if (!((activity?.getSystemService(Context.BLUETOOTH_SERVICE) as
BluetoothManager).adapter.isEnabled)) {
//打开蓝牙开关
activity?.startActivity(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE))
}
requestWindowFeature(Window.FEATURE_NO_TITLE): //去除Activity默认头部
//当Activity继承FragmentActivity时使用:
requestWindowFeature(Window.FEATURE_NO_TITLE)
//当Activity继承AppCompatActivity时使用:
supportRequestWindowFeature(Window.FEATURE_NO_TITLE)