Java 当按钮中的背景色属性为默认值时,如何更改android中单击按钮的背景色? 这些是我在这个按钮中使用的属性。 我还创建了一个XML文件按钮\圆角\视图。 这是我为更好地显示按钮而创建的XML文件属性。 请为我提供这个问题的最佳答案,并告诉我如何停止

Java 当按钮中的背景色属性为默认值时,如何更改android中单击按钮的背景色? 这些是我在这个按钮中使用的属性。 我还创建了一个XML文件按钮\圆角\视图。 这是我为更好地显示按钮而创建的XML文件属性。 请为我提供这个问题的最佳答案,并告诉我如何停止,java,android-studio,button,onclick,background-color,Java,Android Studio,Button,Onclick,Background Color,默认情况下应用于按钮的背景色调属性 These are the attributes I have used in this button. I have also created one XML file button_round_corner_view. <Button android:id="@+id/true_button"

默认情况下应用于按钮的背景色调属性

      These are the attributes I have used in this button.
        I have also created one XML file button_round_corner_view.
           
           <Button
                        android:id="@+id/true_button"
                        android:layout_width="90dp"
                        android:layout_height="50dp"
                        android:layout_margin="10dp"
                        android:background="@drawable/button_round_corner_view"
                        android:padding="10dp"
                        android:text="True"
                        android:textColor="#000000"
                        android:textStyle="bold"
                        app:backgroundTint="#F8F4F4"
                        />
                
    This is the XML file attribute that I have created for a better button look.
please provide me the best answer for this problem and also tell me how to stop 

按钮中的BackgroundTint属性是默认值。我想在用户单击按钮时更改按钮的背景色。
如何做到这一点。请帮帮我。

例如,让我们说有按钮1,这样它就会像

   <?xml version="1.0" encoding="utf-8"?>
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
        
            <corners
                android:radius="20dp"/>
        
            <!-- This is the border color -->
            <stroke
                android:width="2dp"
                android:color="@color/purple_700"/> 
      
            <!-- This is the background color -->
            <solid
                android:color="@color/white"/> 

        </shape>
                                                   

你可以这样做。这就是更改按钮颜色的方式。

当用户为了某些效果而正确触摸按钮时,是否要更改颜色?例如,当用户单击“真”或“假”按钮时,答案是对的或错的,根据正确答案的情况,我要将按钮背景颜色更改为绿色,对于错误的答案,我想更改按钮背景颜色,因为redbackground Tint属性为defaultOk,我知道了,让我写代码并在回答中发帖你迟到了,我昨天得到了答案,简单的解决方案将按钮的backgroundTint属性值设置为=“@null”然后把if-else条件放在上面,就像你写的那样,这样就解决了这个问题。感谢您抽出时间。我已经使用了get-drawable的set-background属性,并且在drawable目录中创建了xml文件。我的解决方案和你的不同。哦,很高兴知道这一点。
button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(Answer.equals("Correct")){
                button1.setBackgroundColor(mContext.getResources().getColor(R.color.DarkGreen));
                
            }else if(Answer.equals("InCorrect")){
                button1.setBackgroundColor(mContext.getResources().getColor(R.color.red));
            }
                
            }
        });