Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 可绘制图标不是';t显示在按钮上_Android_Android Button_Material Components_Material Components Android - Fatal编程技术网

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非常感谢