web-dev-qa-db-fra.com

Comment définir chipText sur com.google.Android.material.chip.Chip?

J'étudie les composants matériels fournis par

implementation group: 'com.google.Android.material', name: 'material', version: '1.0.0-alpha3'

à savoir com.google.Android.material.chip.Chip

Utiliser la version Android Studio

Android Studio 3.2 Canary 18
Build #AI-181.4892.42.32.4830125, built on June 8, 2018
JRE: 1.8.0_152-release-1136-b04 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.11.6

J'ai créé une application de base avec ce grade

apply plugin: 'com.Android.application'

Android {
    compileSdkVersion 'Android-P'
    defaultConfig {
        applicationId "com.research.peanut"
        minSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-Android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

    implementation group: 'com.google.Android.material', name: 'material', version: '1.0.0-alpha3'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
}

Suite à ce site

J'ai ajouté les puces suivantes à mon layout.xml

<?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"
    tools:context=".MainActivity">

    <com.google.Android.material.chip.Chip
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        app:chipText="@string/hello_world" />

    <com.google.Android.material.chip.Chip
        style="@style/Widget.MaterialComponents.Chip.Entry"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        app:chipIcon="@drawable/ic_add_circle_outline_24dp"
        app:chipText="@string/hello_world" />

    <com.google.Android.material.chip.Chip
        style="@style/Widget.MaterialComponents.Chip.Filter"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        app:chipText="@string/hello_world" />

    <com.google.Android.material.chip.Chip
        style="@style/Widget.MaterialComponents.Chip.Choice"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        app:chipText="@string/hello_world"/>


    <com.google.Android.material.chip.Chip
        style="@style/Widget.MaterialComponents.Chip.Action"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        app:chipIcon="@drawable/ic_call_to_action_24dp"
        app:chipText="@string/hello_world"/>

</LinearLayout>

Je reçois les problèmes de construction suivants

Android resource linking failed
Output:  /Users/frankb/AndroidStudioCanaryProjects/wip/Peanut/app/src/main/res/layout/activity_main.xml:10: error: attribute chipText (aka com.research.peanut:chipText) not found.
/Users/frankb/AndroidStudioCanaryProjects/wip/Peanut/app/src/main/res/layout/activity_main.xml:15: error: attribute chipText (aka com.research.peanut:chipText) not found.
/Users/frankb/AndroidStudioCanaryProjects/wip/Peanut/app/src/main/res/layout/activity_main.xml:22: error: attribute chipText (aka com.research.peanut:chipText) not found.
/Users/frankb/AndroidStudioCanaryProjects/wip/Peanut/app/src/main/res/layout/activity_main.xml:28: error: attribute chipText (aka com.research.peanut:chipText) not found.
/Users/frankb/AndroidStudioCanaryProjects/wip/Peanut/app/src/main/res/layout/activity_main.xml:35: error: attribute chipText (aka com.research.peanut:chipText) not found.
error: failed linking file resources.

Qu'est-ce que je rate?

UPDATE

quand un changement ma dépendance de grade à

implementation group: 'com.google.Android.material', name: 'material', version: '1.0.0-alpha1'

Mon application fonctionne bien.

6
Hector

La version 1.0.0-beta01 est sortie et le texte peut maintenant être défini via Android:text

7
MClondi

Juste parce que les puces extends Button puis TextView nous pouvons utiliser

<Android.support.design.chip.Chip
 .
 .
Android:text="text"/>
1
Philipp Buhaievskiy