質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

解決済

1回答

1402閲覧

CoordinatorLayoutを使う時、どのサポートライブラリを使えばいいのか

morin

総合スコア57

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2020/05/21 13:15

CoordinatoryLayoutを使ってみたいと思ってます。

まずは基本的な部分を作ろうと思って、CoordinatoryLayoutの中に、AppBarLayout, NestedScrollViewを入れ、適当にTextViewを表示しようとしました。

しかし、『My application keeps stopping』と表示されて、アプリは起動しません。

build.gradle(Module:app)の最後の行、 implementation 'com.android.support:design:28.0.0'に赤い波線が引かれていたので、多分ここが間違ってる気がするのですが、どうにも、僕には調べてもさっぱりわかりません。

どなたかエラーの原因を教えてください。

ーーーーーーーーーーーーーーーーーーーーーーーーーー

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" > <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/toolbar"> <androidx.appcompat.widget.Toolbar android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_scrollFlags="scroll|enterAlways"/> </com.google.android.material.appbar.AppBarLayout> <androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/appbar_scrolling_view_behavior"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="tv_article"/> </androidx.core.widget.NestedScrollView> </androidx.coordinatorlayout.widget.CoordinatorLayout>

strings.xml

strings.xml

1<resources> 2 <string name="app_name">My Application</string> 3 <string name="msg">msg</string> 4 <string name="toolbar_title">title</string> 5</resources> 6

MainActivity.kt

MainActivity.kt

1package com.example.myapplication 2 3import androidx.appcompat.app.AppCompatActivity 4import android.os.Bundle 5import androidx.appcompat.widget.Toolbar 6 7class MainActivity : AppCompatActivity() { 8 9 override fun onCreate(savedInstanceState: Bundle?) { 10 super.onCreate(savedInstanceState) 11 setContentView(R.layout.activity_main) 12 13 val toolbar = findViewById<Toolbar>(R.id.toolbar) 14 toolbar.setTitle(R.string.toolbar_title) 15 setSupportActionBar(toolbar) 16 } 17}

build.gradle(Module:app)

build.gradle(Module:app)

1dependencies { 2 implementation fileTree(dir: 'libs', include: ['*.jar']) 3 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 4 implementation 'androidx.appcompat:appcompat:1.1.0' 5 implementation 'androidx.core:core-ktx:1.2.0' 6 implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 7 testImplementation 'junit:junit:4.12' 8 androidTestImplementation 'androidx.test.ext:junit:1.1.1' 9 androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 10 implementation 'com.android.support:design:28.0.0' 11}

strings.xml

strings.xml

1<resources> 2 <string name="app_name">My Application</string> 3 <string name="msg">msg</string> 4 <string name="toolbar_title">title</string> 5 <string name="tv_article">msgmsgmsg</string> 6</resources> 7

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Androidでは従来のSupport LibraryからAndroidXへの移行を進めています。両者は混在させることはできないので、"androidx"から始まるビルドアーティファクトが用いられているところに"com.android.support"から始まるものを追加することはできません。ですから、"com.android.support:design"に代わるものを記述する必要があります。

対応表は下記にあります。
アーティファクトのマッピング | Android Developers

これによると、"com.android.support:design"に対応するのは"com.google.android.material:material-rc01"になっているのですが、-rc01(rcは「リリース候補版」の意味で使われることが多い)はいらないみたいですね。

gradle

1 implementation 'com.google.android.material:material:1.1.0'

を追加することで解決できないでしょうか。

投稿2020/05/21 14:28

keicha_hrs

総合スコア6768

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問