using Kotlin 1.20.20 (not that it matters, older versions behaves the same)
When layout is in separate library module Android Studio has no problem finding and refer
Do not import the following library import kotlinx.android.synthetic.main.my_view.view.*
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val view: View = MyView(this)
view.findViewById(R.id.textViewPocLib).text = "I can edit the library components"
setContentView(view)
}
class MyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
LinearLayout(context, attrs, defStyleAttr) {
init {
LayoutInflater.from(context)
.inflate(R.layout.my_view, this, true)
}
}
GL
Sources: