0

我在编程方面很菜鸟,我一直在学习一些教程,并且我更改了样式或颜色或其他内容,现在我遇到的问题是,当我尝试创建按钮时,它以特定颜色开始为此,它不允许我设置我以前做过的背景资源。

我怎样才能让按钮显示这个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>

这是我想使用的drawable

可绘制按钮

这是我设置了背景但未显示的按钮

没有显示棕色和背景的按钮

<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>
4

2 回答 2

0

在约束布局设置的根目录中删除相同的可绘制 .pls。

于 2020-03-07T17:52:51.923 回答
0

您必须使用 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" />
于 2020-03-07T19:29:01.150 回答