Home > Enterprise >  My custom button for my Android Application isnt working
My custom button for my Android Application isnt working

Time:10-18

I am trying to get a custom button for my Android App. The problem is, that the colours/gradiant arent applied to the button background, but the Radius is. Can anyone tell me why?

button_pressed.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <gradient android:startColor="#8D2AF598" android:endColor="#8A009EFD" android:type="linear" />
    <corners android:radius="50dp" />
</shape>

button_disabled.xml and button_default.xml are the same

Custom_button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:drawable="@drawable/button_disabled" />
    <item android:state_pressed="true" android:drawable="@drawable/button_pressed" />
    <item android:drawable="@drawable/button_default"/>
</selector>

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:screenOrientation="portrait"
        tools:context=".MainActivity"
        android:theme="@style/Theme.HandballTippspiel"
        android:background="#393838">

    <Button android:id="@ id/btnMakeGuess"
            android:layout_width="222dp"
            android:layout_height="48dp"
            android:text="Tipps Abgeben"
            android:background="@drawable/button_default"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" app:layout_constraintHorizontal_bias="0.497"
            app:layout_constraintVertical_bias="0.366"/>

    <Button android:id="@ id/btnSeeLeaderboard"
            android:layout_width="222dp"
            android:layout_height="48dp"
            android:text="Scoreboard"
            app:layout_constraintBottom_toBottomOf="parent"
            android:background="@drawable/button_default"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" app:layout_constraintHorizontal_bias="0.497"
            app:layout_constraintVertical_bias="0.541"/>

    <Button android:id="@ id/btnSeeGuesses"
            android:layout_width="222dp"
            android:layout_height="48dp"
            android:text="Tipps ansehen"
            android:background="@drawable/button_default"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" app:layout_constraintHorizontal_bias="0.497"
            app:layout_constraintVertical_bias="0.452"/>
</androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

may be your activity theme is parent="Theme.MaterialComponents.DayNight.NoActionBar,u can change theme to ...DayNight.Bridge or use TextView replace Button.

  • Related