这两个实现之间有什么区别?
DrawableCompat.setTintMode(wrappedDrawable, Mode.SRC_ATOP);
DrawableCompat.setTint(wrappedDrawable, color);
Run Code Online (Sandbox Code Playgroud)
和
drawable.setColorFilter(color, Mode.SRC_ATOP);
Run Code Online (Sandbox Code Playgroud) 我无法获得带有合并根标记的布局来处理视图绑定。是否可以?
include_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/include_test"
layout="@layout/merge_layout"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
合并布局.xml:
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/include_test">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A Title"/>
</merge>
Run Code Online (Sandbox Code Playgroud)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = IncludeLayoutBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.includeTest.title.text = "New Title"
}
Run Code Online (Sandbox Code Playgroud)
运行时异常:
java.lang.NullPointerException: Missing required view with ID: includeTest