我正在使用MaterialButton
和使用app:srcCompat
,但不幸的是图标没有显示。尝试了矢量可绘制对象和 webp 图像,但没有任何效果。
<com.google.android.material.button.MaterialButton
android:id="@+id/facebookButton"
style="@style/ButtonS.Normal"
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_48"
android:layout_marginTop="@dimen/spacing_8"
android:background="@drawable/bg_blue_round_corner"
android:gravity="center"
android:text="@string/welcome_screen_continue_with_facebook"
app:srcCompat="@drawable/ic_facebook"
app:iconGravity="textStart"
app:iconPadding="7dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
有谁知道为什么它不起作用?
注意:我必须需要使用app:srcCompat
而不是app:icon
由于得到一个随机异常,我怀疑它是因为使用了app:icon
Details 堆栈跟踪:
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.client/com.android.onboarding.welcome.ui.WelcomePageActivity}: android.view.InflateException: Binary XML file line #264 in com.android.client:layout/activity_landing_page: Binary XML file line #264 in com.android.client:layout/activity_landing_page: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3477)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3620)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2183)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:7617)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
以及发生异常的 XML 第 264 行:
<com.google.android.material.button.MaterialButton
.......
app:layout_constraintTop_toBottomOf="@+id/emailButton" /> // Line 264