简体   繁体   English

为什么膨胀和根警告我?

[英]why do inflate and root warn me?

class MainActivity : AppCompatActivity() { 

    lateinit var binding: ActivityMainBinding 
    
    override fun onCreate(savedInstanceState: Bundle?) { 
        super.onCreate(savedInstanceState) 
        binding = ActivityMainBinding.inflate(layoutInflater, AppCompatActivity(),true)
        setContentView(binding.root) 
    }

Try to inflate your layout with ActivityMainBinding.inflate(layoutInflater) and make the binding variable private:尝试使用ActivityMainBinding.inflate(layoutInflater)来扩充您的布局,并将binding变量设为私有:

class MainActivity : AppCompatActivity() { 

    private lateinit var binding: ActivityMainBinding 
    
    override fun onCreate(savedInstanceState: Bundle?) { 
        super.onCreate(savedInstanceState) 
        binding = ActivityMainBinding.inflate(layoutInflater) 
        setContentView(binding.root) 
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么没有指定根目录的“ inflate”方法会忽略xml参数? - Why “inflate” method without specified root ignores the xml parameters? 为什么生成的视图 binding.inflate() 方法需要 root 参数? - Why does the generated view binding .inflate() method requires root parameter? 为什么LayoutInflater.inflate返回作为参数传递的根? - Why LayoutInflater.inflate returns the root passed as parameter? 为什么将 LayoutInflater 传递给 inflate()? - Why do you pass LayoutInflater to inflate()? 为什么我会收到Layout inflate异常? - why do i get a Layout inflate exception? 为什么我们需要在活动中使用 Fragment 的组件时对其进行膨胀? - Why do we need to inflate components of fragment while using it in an activity? 在“ inflate”或addView中设置根视图 - Set root view in “inflate” or addView 为什么我在模拟器上出现 Inflate 异常,但在我的 Droid 上却没有? - Why do i get an Inflate exception on the emulator but not on my Droid? 为什么从inflate()返回的根View与从findViewById()返回的View不匹配? - Why root View return from inflate() does not match with View returned from findViewById()? 为什么android studio会警告我有关为输入项创建通用数组的信息 - Why does android studio warn me about generic array creation for typed entry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM