Android Studio Chipmunk(シマリス)が最近リリースされたので、
グラフを描画するライブラリ(MPAndroidChart)の取り込み方を調べた。
公式(https://github.com/PhilJay/MPAndroidChart)を見て最新バージョンを確認!
本当は公式のSetUpを見れば誰でも取り込めるようになってたら良かったんだけど
分かりにくかったので、まとめます。
Android Studio Chipmunk(シマリス)が最近リリースされたので、
グラフを描画するライブラリ(MPAndroidChart)の取り込み方を調べた。
公式(https://github.com/PhilJay/MPAndroidChart)を見て最新バージョンを確認!
本当は公式のSetUpを見れば誰でも取り込めるようになってたら良かったんだけど
分かりにくかったので、まとめます。
java言語のString#splitを使い文字列を配列に分解する時、
引数で指定した文字列は配列から消えるが、要素内に入れたい場合がある。
例えば
String str = "{あいうえお}{かきくけこ}{さしすせそ}";
// これを{}を残したまま以下のように分解したい
String[] result = {
"{あいうえお}",
"{かきくけこ}",
"{さしすせそ}"
};
正規表現の「先読み」「後読み」を使うことで対応できる。
AndroidでToolbarを使いMenu表示させると、
以下のように文字が見えず空欄のMenuが表示されてしまう。
これはMenuの文字色が白、背景色も白であることが原因だった。
なのでMenuの文字色を調整する方法を記載する。
メールアドレスのみで認証する、パスワード設定が不要な認証方法です。
// 押下したリストのアイテム情報をトースト表示する
listView.setOnItemClickListener { parent, view, position, id ->
Toast.makeText(this, array[position], Toast.LENGTH_SHORT).show()
}
こうすると、Build file 'E:\Document\MyApplication11\app\build.gradle' line: 2
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories. This repository is deprecated and it will be shut down in the future. See http://developer.android.com/r/tools/jcenter-end-of-service for more information. Currently detected usages in: root project 'My Application', project ':app' Affected Modules: app
どうやら「jcenter()が非推奨になって、じきに完全消滅するから、ビルドスクリプトから消してくれ」とのこと
A problem occurred configuring root project 'My Application'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10-release-894.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.10-release-894/kotlin-gradle-plugin-1.5.10-release-894.pom
- https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.10-release-894/kotlin-gradle-plugin-1.5.10-release-894.pom
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
どうやらkotlinのプラグイン「1.5.10-release-894」が見つからないらしい。。
AndroidStudio4.2がリリースされたのでアップデートしてみたら
新規プロジェクトをKotlinで作成すると、以下のエラーが出てビルドできなくなった。
A problem occurred configuring root project 'My Application'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0-release-764.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.0-release-764/kotlin-gradle-plugin-1.5.0-release-764.pom
- https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.0-release-764/kotlin-gradle-plugin-1.5.0-release-764.pom
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
どうやらkotlinのプラグイン「1.5.0-release-764」が見つからないらしい。。
Fragmentをpublic以外のアクセス修飾子でクラス定義していると、FragmentManagerに追加する際、以下のIllegalStateExceptionが投げられクラッシュする。
Caused by: java.lang.IllegalStateException: Fragment com.sample.test.myapplication.MainActivity.MyDialogFragment must be a public static class to be properly recreated from instance state. at androidx.fragment.app.FragmentTransaction.doAddOp(FragmentTransaction.java:165) at androidx.fragment.app.BackStackRecord.doAddOp(BackStackRecord.java:179) at androidx.fragment.app.FragmentTransaction.add(FragmentTransaction.java:125) at androidx.fragment.app.DialogFragment.show(DialogFragment.java:154) at com.sample.test.myapplication.MainActivity.onClick(MainActivity.java:32)
AndroidアプリでButtonの上にViewやFragmentを乗せても、
Buttonが表示物に隠れず、ボタンが上に重なって表示される。
解決方法として、ボタンの属性「stateListAnimator」に「"@null"」を設定すれば良い。
例えば、ボタンの上に画像(ImageView)を配置したいときは以下のようにする。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:stateListAnimator="@null" ★ コレ! ★
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Androidは公式がGitHubにサンプルプロジェクトを公開している。
これらのサンプルコードを取り込んでビルドしたいときの方法を残しておく。
※GitHubからソースコードを落としたいだけなら、手順2までで良い