20210106のAndroidに関する記事は3件です。

【Android】スイッチボタンのつまみの画像をON/OFFで変更

まず、つまみ用の画像の設定

thumb_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/sun" android:state_checked="false" />
    <item android:drawable="@drawable/night" android:state_checked="true" />
</selector>

次に、背景設定

background_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false">
        <shape android:shape="rectangle">
            <solid android:color="@color/white" />
            <corners android:radius="20dp" />
        </shape>
    </item>
    <item android:state_checked="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/black" />
            <corners android:radius="20dp" />
        </shape>
    </item>
</selector>

透明なスタイルに変更

style.xml
    <style name="Switch" parent="Theme.AppCompat.Light">
        <item name="colorControlActivated">#00000000</item>
        <item name="android:colorForeground">#00000000</item>
        <item name="colorControlHighlight">#00000000</item>
    </style>

これらを組み合わせて、スイッチボタンを作成。

switch.xml
<androidx.appcompat.widget.SwitchCompat
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background_switch"
    android:theme="@style/SlideButton"
    android:thumb="@drawable/thumb_switch"/>
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

EncryptedSharedPreferencesのところで落ちる件

ただの備忘録なのであまり本質的でないです。

困ったこと

昨日まで動いていた開発中のAndroidアプリが、エミュレータ上で落ちる。

どこで落ちているか

ここ。つまりEncryptedSharedPreferencesを開くところ。

    @Synchronized
    fun getPreferences(): SharedPreferences {
        val masterKey = MasterKey.Builder(getApplication(), MasterKey.DEFAULT_MASTER_KEY_ALIAS)
                .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
                .build()
        return EncryptedSharedPreferences.create(getApplication(),
                "my_app",
                masterKey,
                EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
                EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM)
    }

※「ここを呼び出している大元のクラス」が例外を吐いた後、改めてここが例外を吐くので、一見気付かないことがある(これではまった)。

何が原因か

エミュレータおよび一部実機のAndroidKeyStoreの実装がおかしいらしい。

ワークアラウンド

AVD Managerで当該エミュレータのAVDを Stop→Wipe Data→Launch してから改めてアプリを起動。
androidx.security:security-crypto ライブラリのバージョンによって治ったり治らなかったりするいう報告もあり。

参考

Google Issue Tracker

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Android レビューダイアログ メモ

参考記事

レビューダイアログの表示方法
https://ameblo.jp/highcommunicate/entry-12554726670.html

main_activityが解決されないエラー
https://teratail.com/questions/248389

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む