Нажатие кнопки не работает с дизайном материала? - PullRequest
1 голос
/ 10 января 2020

Я использовал Material Design Library для создания кнопки, и я сделал дизайн правильно, и код был верным, но он не реагирует на нажатия, что я могу сделать для кнопки, которая реагирует на нажатие, я хочу изменить часть кода, чтобы кнопка работала.

MainActivity

public class MainActivity extends AppCompatActivity {

                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_main);

                    ButtonRectangle buttonSelectColor = (ButtonRectangle) findViewById(R.id.button4);

                    buttonSelectColor.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                          Log.i("trace","don");

                        }
                    });
                }
                // End ;
            }

XML

<?xml version="1.0" encoding="utf-8"?>
                <RelativeLayout
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:tools="http://schemas.android.com/tools"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#ffffff"
                    tools:context=".MainActivity">


                    <com.gc.materialdesign.views.ButtonRectangle
                        android:id="@+id/button4"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="#1E88E5"
                        android:text="Button6787" />

                </RelativeLayout>

gradle.dependencies

apply plugin: 'com.android.application'

                android {
                    compileSdkVersion 29
                    buildToolsVersion "29.0.1"
                    defaultConfig {
                        applicationId "com.ahmedco.testcode2"
                        minSdkVersion 15
                        targetSdkVersion 29
                        versionCode 1
                        versionName "1.0"
                        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
                    }
                    buildTypes {
                        release {
                            minifyEnabled false
                            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
                        }
                    }
                }

                dependencies {
                    implementation fileTree(dir: 'libs', include: ['*.jar'])
                    implementation 'androidx.appcompat:appcompat:1.1.0'
                    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
                    testImplementation 'junit:junit:4.12'
                    androidTestImplementation 'androidx.test:runner:1.2.0'
                    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
                    implementation 'com.github.navasmdc:MaterialDesign:1.5@aar'
                }
...