android - 如果其他情况,Android kotlin 导入合成
问题描述
有什么方法可以导入合成布局,例如:
If (App.layout1) import ...layout1 else layout2
?
我基本上需要这个功能;)谢谢
解决方案
我知道你可以在 kotlin 中重命名导入
import kotlinx.android.synthetic.activity1.someView as value1
import kotlinx.android.synthetic.activity2.someView as value2
但这可能会导致您手动手动导入所有视图。(未测试)也许您可以导入整个合成类而不是所有视图
import kotlinx.android.synthetic.activity1 as views1
import kotlinx.android.synthetic.activity2 as views2
接着
if (...) views1.someView.stuff() else views2.someView.stuff()
可能不支持条件导入,因为 Java 不支持它。
推荐阅读
- stm32 - 如何使用STM32F4从MPU6050读取数据
- javascript - 如何替换 Mozilla 中的 getUserMedia 函数?
- javascript - 匹配数组中的 3 个或更多相同元素并将它们添加到列表中
- webpack - SCSS 文件无法使用 webpack/next.js 加载
- gmail - 将 G Suite 迁移到两个单独的 G Suite
- c# - 在 wpf C# xaml 中创建 tabitem?
- c# - 如何通过 ajax 使用 Bootstrap4 自定义文件上传来上传文件
- java - while 循环里面的 for 循环,困惑?
- node.js - 将 Angular 应用程序部署到 Heroku 时出现“未找到”错误
- flutter - 颤振 location.altitude 返回 0.0