添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am investigating the material components provided by

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

namely com.google.android.material.chip.Chip

Using Android Studio version

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

I created a basic application with this gradle

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'

Following this site

I added the following chips to my 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>

I get have the following build issues

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.

What am I missing?

UPDATE

when a change my gradle dependency to

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

My app works fine.

I'm experiencing the same issue after updating it to 1.0.0-alpha03. Setting chipText programatically works btw. – Nominalista Jun 12, 2018 at 15:38 @Nominalista, when I set chip text programatically the displayed chip text is not displayed correctly as the chips size (width) is set as if it has no text. How are you getting the text displayed in full? – Hector Jun 12, 2018 at 15:54

Just because the Chips extends Button and then TextView we are able to use

<android.support.design.chip.Chip
android:text="text"/>
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.