要在按钮上添加图标,drawableTop无法在Android上运行
我想在按钮上添加呼叫图标,但drawableTop不工作要在按钮上添加图标,drawableTop无法在Android上运行,android,android-layout,android-drawable,android-button,Android,Android Layout,Android Drawable,Android Button,我想在按钮上添加呼叫图标,但drawableTop不工作 <LinearLayout android:layout_width="match_parent" android:layout_height="60dp"> <Button android:id="@+id/imageView3" android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<Button
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:drawableTop="@android:drawable/ic_menu_call"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
为您的
线性布局添加方向
,在设置android:layout\u weight=“match\u parent”和android:layout\u height=“match\u parent”时,决定是否要设置android:layou weight
并将文本设置为按钮。您还可以在drawableStart中定义图标,如下所示:
<Button
android:id="@+id/imageView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black_overlay"
android:drawableStart="@drawable/ic_menu_call"
android:padding="15dp"
android:text="Click here"
android:textStyle="bold" />
填充、文本样式和背景色仅用于装饰。用AppCompatButton
替换您的按钮
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<android.support.v7.widget.AppCompatButton
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@android:drawable/ic_menu_call"/>
</LinearLayout>
将androidx与材质ui库而不是支持库一起使用时
implementation 'com.google.android.material:material:1.0.0'
您需要使用
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@android:drawable/ic_menu_camera"
android:text="Camera" />
同时使用您的相同代码,我可以看到drawableTop
实际上我使用的是android:drawableLeft,这也不起作用。您的drawable的色调是否与背景颜色相同?您是否有可能使用新材质库而不是设计支持库?您是否使用新材质库代替支持库?我正在使用com.android。支持:设计:28.0.0您知道我们需要使用drawableTop而不是图标的原因吗?