AppCompatViewInflater: EditText被自动转换为AppCompatEditText

Activity 必须是:AppCompatActivity
xml 中有:EditText,不能被继承

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/image_view"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginBottom="12dp" />

    <EditText
        android:id="@+id/my_input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="30dp"
        android:text="Hello World!"/>

</LinearLayout>

具体看:AppCompatViewInflater 的 createView方法
请添加图片描述

uml code

@startuml
'https://plantuml.com/sequence-diagram


AppCompatActivity --> AppCompatDelegateImpl : setContentView
AppCompatDelegateImpl --> LayoutInflater : inflate
LayoutInflater --> LayoutInflater : createViewFromTag
LayoutInflater --> LayoutInflater : tryCreateView
LayoutInflater --> AppCompatDelegateImpl : createView
AppCompatDelegateImpl --> AppCompatViewInflater : createView


@enduml

版权声明:本文为m0_37746212原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。