Search code examples
androidmaterial-designandroid-buttonmaterial-componentsmaterial-components-android

I cant use material button using com.google.android.material.button.MaterialButton


Hi i want use material buttons like buttons in links below: https://material.io/components/buttons/#text-button

but when i added:

compile group: 'com.google.android.material', name: 'material', version: '1.1.0-alpha01'

and used :

my codes are in below

i had already used many com.google.android.material implementations but cant do so some of my tries:

implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.0.0-alpha1'

app gradle:


android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.esppad.fansy4"
        minSdkVersion 21
        targetSdkVersion 28
        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.0.0'
    // https://mvnrepository.com/artifact/com.google.android.material/material
    compile group: 'com.google.android.material', name: 'material', version: '1.1.0-alpha01'

    //implementation 'com.google.android.material:material:1.1.0-alpha1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

and my main activity code is:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 android:layout_marginLeft="10dp"
 android:layout_marginRight="10dp"
 android:gravity="center">
 <com.google.android.material.button.MaterialButton
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     style="@style/Widget.MaterialComponents.Button.OutlinedButton"
     android:text="material"
     app:strokeColor="@color/colorPrimary"
     app:strokeWidth="2dp"
     android:layout_marginBottom="10dp"

     />

     <Button
         android:id="@+id/button"
         style="@style/Widget.MaterialComponents.Button.TextButton"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Button" />

 <Button
     android:id="@+id/button2"

     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:text="Button" />
</LinearLayout>

my build gradle is:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Solution

  • Try this implementation 'com.google.android.material:material:1.0.0'
    OR try to migrate your app to androidx here is the example