Android 可绘制图标不是';t显示在按钮上
每次我尝试向按钮添加一些可绘制图标时,即使是按钮或材质按钮,它们也不会显示Android 可绘制图标不是';t显示在按钮上,android,android-button,material-components,material-components-android,Android,Android Button,Material Components,Material Components Android,每次我尝试向按钮添加一些可绘制图标时,即使是按钮或材质按钮,它们也不会显示 <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Perso
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Person"
android:drawableStart="@drawable/ic_person_pin_circle_black_24dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Package"
android:layout_marginStart="10dp"
android:drawableStart="@drawable/ic_business_center_black_24dp"
/>
在左边我有“个人密码”图标和“公文包”图标,但在布局上没有显示。您知道这可能是什么原因吗?drawableStart对应于将根据布局方向绘制到视图开始处的drawable,但您的方向可能不好;您可以这样更改此方向: android:gravity=“中心垂直|中心水平|左侧” 或者您可以通过编程方式添加它们:
myButton.setCompoundDrawablesRelativeWithIntrinsicBounds(
ContextCompat.getDrawable(this, R.drawable.ic_business_center_black_24dp), null, null, null);
使用
material按钮
使用应用程序:图标
属性和应用程序:iconGravity=“start”
比如:
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.Icon"
app:icon="@drawable/..."
app:iconGravity="start"
../>
在Material按钮中,您必须使用app:I非常感谢