按钮不显示可绘制背景
Button doesn't show background drawable
我在编程方面相当菜鸟,我一直在学习一些教程,我更改了一些样式或颜色或其他东西,现在我遇到了一个问题,当我尝试创建按钮时,它开始用特定的颜色关闭,为此,它不允许我设置我以前做过的背景资源。
如何让按钮显示这个可绘制对象?
这是 xml(尽管我所有的布局都会出现这种情况)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginStart="100dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="100dp"
android:background="@drawable/button_black_background">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/user_profile_image_search"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:src="@drawable/profile"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/user_name_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="User name"
android:textColor="@color/colorTextPrimary"
android:textSize="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/user_profile_image_search" />
<TextView
android:id="@+id/user_full_name_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="Full name"
android:textColor="@color/colorTextPrimary"
android:textSize="12dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/user_name_search" />
<Button
android:id="@+id/follow_btn_search"
android:layout_width="90dp"
android:layout_height="35dp"
android:background="@drawable/button_black_background"
android:text="Follow"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:padding="2dp"
app:layout_constraintTop_toBottomOf="@+id/user_full_name_search" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
这是我要使用的可绘制对象
这是我设置了背景但未显示的按钮
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_black_background"/>
这些是我的颜色
<resources>
<color name="colorPrimary">#721100</color>
<color name="colorPrimaryDark">#3F0101</color>
<color name="colorAccent">#FF5AB0</color>
<color name="colorTextPrimary">#212121</color>
<color name="colorTextSecondary">#757575</color>
</resources>
这些是我的风格
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
在约束布局的根目录中设置相同的可绘制对象。请从中删除。
您必须使用 androidx 包中的 Button。这段代码,
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/follow_btn_search"
android:layout_width="90dp"
android:layout_height="35dp"
android:background="@drawable/button_black_background"
android:text="Follow"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:padding="2dp"
app:layout_constraintTop_toBottomOf="@+id/user_full_name_search" />
我在编程方面相当菜鸟,我一直在学习一些教程,我更改了一些样式或颜色或其他东西,现在我遇到了一个问题,当我尝试创建按钮时,它开始用特定的颜色关闭,为此,它不允许我设置我以前做过的背景资源。
如何让按钮显示这个可绘制对象?
这是 xml(尽管我所有的布局都会出现这种情况)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginStart="100dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="100dp"
android:background="@drawable/button_black_background">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/user_profile_image_search"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:src="@drawable/profile"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/user_name_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="User name"
android:textColor="@color/colorTextPrimary"
android:textSize="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/user_profile_image_search" />
<TextView
android:id="@+id/user_full_name_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="Full name"
android:textColor="@color/colorTextPrimary"
android:textSize="12dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/user_name_search" />
<Button
android:id="@+id/follow_btn_search"
android:layout_width="90dp"
android:layout_height="35dp"
android:background="@drawable/button_black_background"
android:text="Follow"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:padding="2dp"
app:layout_constraintTop_toBottomOf="@+id/user_full_name_search" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
这是我要使用的可绘制对象
这是我设置了背景但未显示的按钮
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_black_background"/>
这些是我的颜色
<resources>
<color name="colorPrimary">#721100</color>
<color name="colorPrimaryDark">#3F0101</color>
<color name="colorAccent">#FF5AB0</color>
<color name="colorTextPrimary">#212121</color>
<color name="colorTextSecondary">#757575</color>
</resources>
这些是我的风格
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
在约束布局的根目录中设置相同的可绘制对象。请从中删除。
您必须使用 androidx 包中的 Button。这段代码,
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/follow_btn_search"
android:layout_width="90dp"
android:layout_height="35dp"
android:background="@drawable/button_black_background"
android:text="Follow"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:padding="2dp"
app:layout_constraintTop_toBottomOf="@+id/user_full_name_search" />