ソースコード source code

下記アプリの主要なソースコードを公開しています。アプリ開発の参考になれば幸いです。

画像等が別途必要ですので下記情報のみでアプリが完成するものではありません。 アプリは少しずつ機能拡張していますのでストア公開されているアプリと内容が異なる場合があります。 コードはコピーして自由にお使いいただけます。ただし著作権は放棄しておりませんので全部の再掲載はご遠慮ください。部分的に再掲載したり、改変して再掲載するのは構いません。 自身のアプリ作成の参考として個人使用・商用問わず自由にお使いいただけます。 コード記述のお手本を示すものではありません。ミニアプリですので変数名などさほど気遣いしていない部分も有りますし間違いも有るかと思いますので参考程度にお考え下さい。 他の賢者の皆様が公開されているコードを参考にした箇所も含まれます。Androidアプリ開発の熟練者が書いたコードではありません。 エンジニア向け技術情報共有サービスではありませんので説明は省いています。ご了承ください。 GitHubなどへの公開は予定しておりません。

下記コードの最終ビルド日: 2021-10-24

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 30

    defaultConfig {
        applicationId "jp.aosystem.mixingcolors"
        minSdk 21
        targetSdk 30
        versionCode 2
        versionName "1.1"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'com.google.android.gms:play-services-ads:20.4.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

app/src/main/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="jp.aosystem.mixingcolors">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MixingColors">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SettingActivity" />

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-0000000000000000~0000000000" />
    </application>

</manifest>

app/src/main/java/jp/aosystem/mixingcolors/MainActivity.kt

package jp.aosystem.mixingcolors

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.LocaleList
import android.util.DisplayMetrics
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdSize
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.MobileAds
import java.util.*

class MainActivity : AppCompatActivity(), GiveupDialogFragment.GiveupDialogLister {

    private lateinit var vAdContainer: LinearLayout
    private lateinit var vTextSetting: TextView
    private lateinit var vTextLevel: TextView
    private lateinit var vTextNext: TextView
    private lateinit var vTextReset: TextView
    private lateinit var vTextGiveup: TextView
    private lateinit var vTextResume: TextView
    private lateinit var vTextPaintNum: List<TextView>
    private lateinit var vImageStageTarget: ImageView
    private lateinit var vImageStageMix: ImageView
    private lateinit var vImagePaintColor: List<ImageView>
    private lateinit var vImagePaintTray: List<ImageView>

    private var destroyFlag: Boolean = false    //Activity破棄された場合など
    private var themeNumber: Int = 0
    private var localeLanguage: String = ""
    private var gameLevel: Int = 0
    private val gameLevelStep: Int = 6
    private var answer: Array<Int> = arrayOf(0,0,0,0,0,0)
    private var resetCount: Int = 0
    data class Cmy(
        var c: Float,
        var m: Float,
        var y: Float,
    )
    private var paintCmy: Array<Cmy> = arrayOf(
        Cmy(0F,0F,0F),
        Cmy(0F,0F,0F),
        Cmy(0F,0F,0F),
        Cmy(0F,0F,0F),
        Cmy(0F,0F,0F),
        Cmy(0F,0F,0F),
    )
    private val variationCmy: List<Cmy> = listOf(
        Cmy(1F,0F,0F),
        Cmy(0F,1F,0F),
        Cmy(0F,0F,1F),
        Cmy(1F,0.7F,0F),
        Cmy(1F,0F,0.7F),
        Cmy(1F,0.7F,0.7F),
        Cmy(0.5F,1F,0F),
        Cmy(0F,1F,0.7F),
        Cmy(0.7F,1F,0.7F),
        Cmy(0.7F,0F,1F),
        Cmy(0F,0.7F,1F),
        Cmy(0.7F,0.7F,1F),
    )
    //adMob
    private lateinit var adView: AdView     //adMob
    private val adSize: AdSize
        get() {
            val display = windowManager.defaultDisplay
            val outMetrics = DisplayMetrics()
            display.getMetrics(outMetrics)
            val density = outMetrics.density
            var adWidthPixels = this.vAdContainer.width.toFloat()
            if (adWidthPixels == 0f) {
                adWidthPixels = outMetrics.widthPixels.toFloat()
            }
            val adWidth = (adWidthPixels / density).toInt()
            return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth)
        }

    companion object {
        //private const val AD_UNIT_ID: String = "ca-app-pub-0000000000000000/0000000000"     //adMob Test
        internal const val AD_UNIT_ID: String = "ca-app-pub-0000000000000000/0000000000"
        internal const val SETTINGS: String = "settings"
        internal const val GAME_LEVEL: String = "gameLevel"
        internal const val THEME_NUMBER: String = "themeNumber"
        internal const val LOCALE_LANGUAGE: String = "localeLanguage"
        internal const val RESET_GAME_LEVEL: String = "resetGameLevel"
    }

    private val settingStartForResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
        if (result.resultCode == Activity.RESULT_OK) {
            val intent: Intent? = result.data
            if (intent != null) {
                val resetGameLevel = intent.getIntExtra(RESET_GAME_LEVEL, 0)
                if (resetGameLevel == 1) {
                    this.gameLevel = 0
                    this.saveGameLevel()
                }
                val lastThemeNumber: Int = this.themeNumber
                this.themeNumber = intent.getIntExtra(THEME_NUMBER, 0)
                if (lastThemeNumber != this.themeNumber) {
                    this.saveThemeNumber()
                }
                val lastLocaleLanguage = this.localeLanguage
                this.localeLanguage = intent.getStringExtra(LOCALE_LANGUAGE) ?: ""
                if (this.localeLanguage != lastLocaleLanguage) {
                    this.saveLocaleLanguage()
                }
                recreate()
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        //タイトルバー非表示
        supportActionBar?.hide()
        //
        this.vAdContainer = findViewById(R.id.ad_container)
        this.vTextSetting = findViewById(R.id.textSetting)
        this.vTextLevel = findViewById(R.id.textLevel)
        this.vTextNext = findViewById(R.id.textNext)
        this.vTextReset = findViewById(R.id.textReset)
        this.vTextGiveup = findViewById(R.id.textGiveup)
        this.vTextResume = findViewById(R.id.textResume)
        this.vTextPaintNum = listOf(
            findViewById(R.id.textPaintNum1),
            findViewById(R.id.textPaintNum2),
            findViewById(R.id.textPaintNum3),
            findViewById(R.id.textPaintNum4),
            findViewById(R.id.textPaintNum5),
            findViewById(R.id.textPaintNum6),
        )
        this.vImageStageTarget = findViewById(R.id.imageStageTarget)
        this.vImageStageMix = findViewById(R.id.imageStageMix)
        this.vImagePaintColor = listOf(
            findViewById(R.id.imagePaintColor1),
            findViewById(R.id.imagePaintColor2),
            findViewById(R.id.imagePaintColor3),
            findViewById(R.id.imagePaintColor4),
            findViewById(R.id.imagePaintColor5),
            findViewById(R.id.imagePaintColor6),
        )
        this.vImagePaintTray = listOf(
            findViewById(R.id.imagePaintTray1),
            findViewById(R.id.imagePaintTray2),
            findViewById(R.id.imagePaintTray3),
            findViewById(R.id.imagePaintTray4),
            findViewById(R.id.imagePaintTray5),
            findViewById(R.id.imagePaintTray6),
        )
        //
        //テーマ読み込みと設定
        this.loadThemeNumber()
        this.setTheme()
        //設定読み出し
        this.loadGameLevel()
        //onClickListener
        this.vTextSetting.setOnClickListener {
            this.onClickSetting()
        }
        this.vTextReset.setOnClickListener {
            this.onClickReset()
        }
        this.vTextGiveup.setOnClickListener {
            this.onClickGiveup()
        }
        this.vTextResume.setOnClickListener {
            this.onClickResume()
        }
        this.vTextNext.setOnClickListener {
            this.onClickNext()
        }
        for (i in 0..5) {
            this.vImagePaintColor[i].setOnClickListener {
                this.onClickPaintColor(i)
            }
        }
        //adMob
        MobileAds.initialize(this) {}
        this.adView = AdView(this)
        this.vAdContainer.addView(this.adView)
        this.loadBanner()
    }

    override fun onResume() {
        super.onResume()
        this.game()
    }

    override fun onDestroy() {
        this.destroyFlag = true
        super.onDestroy()
    }

    //adMob
    private fun loadBanner() {
        this.adView.adUnitId = AD_UNIT_ID
        this.adView.adSize = this.adSize
        val adRequest = AdRequest
            .Builder()
            //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build()
        this.adView.loadAd(adRequest)
    }

    //-------------------------------------------------

    private fun gameLargeStep(): Int {
        return (this.gameLevel / this.gameLevelStep).toInt()
    }

    private fun gameSmallStep(): Int {
        return this.gameLevel % this.gameLevelStep
    }

    private fun game() {
        this.destroyFlag = false
        this.vTextReset.alpha = 0F
        this.vTextGiveup.alpha = 0F
        this.vTextNext.alpha = 0F
        this.vTextResume.alpha = 0F
        for (i in 0..5) {
            this.setPaintAlpha(i,0)
            this.vTextPaintNum[i].text = "0"
            this.vTextPaintNum[i].setTextColor(ContextCompat.getColor(this,R.color.text))
            this.vTextPaintNum[i].setBackgroundColor(Color.TRANSPARENT)
        }
        this.setMixColor(Color.rgb(255, 255, 255))
        this.quest()
        this.setPaintColor(0)
        this.setPaintColor(1)
        this.setPaintAlpha(0,1)
        this.setPaintAlpha(1,1)
        if (this.gameLargeStep() > 0) {
            this.setPaintColor(2)
            this.setPaintAlpha(2, 1)
        }
        if (this.gameLargeStep() > 1) {
            this.setPaintColor(3)
            this.setPaintAlpha(3,1)
        }
        if (this.gameLargeStep() > 2) {
            this.setPaintColor(4)
            this.setPaintAlpha(4,1)
        }
        if (this.gameLargeStep() > 3) {
            this.setPaintColor(5)
            this.setPaintAlpha(5,1)
        }
        this.vTextLevel.text = resources.getText(R.string.level).toString() + ": " + (this.gameLevel + 1).toString()
        this.resetCount = 0
    }

    private fun quest() {
        this.answer = arrayOf(0,0,0,0,0,0)
        val list: List<Int> = listOf(0,1,2,3,4,5,6,7,8,9,10,11).shuffled()
        this.paintCmy[0] = this.variationCmy[list[0]]
        this.paintCmy[1] = this.variationCmy[list[1]]
        this.answer[0] = ((this.gameSmallStep() + 1) * Math.random()).toInt() + 1
        this.answer[1] = ((this.gameSmallStep() + 1) * Math.random()).toInt() + 1
        if (this.gameLargeStep() > 0) {
            this.paintCmy[2] = this.variationCmy[list[2]]
            this.answer[2] = ((this.gameSmallStep() + 1) * Math.random()).toInt() + 1
        }
        if (this.gameLargeStep() > 1) {
            this.paintCmy[3] = this.variationCmy[list[3]]
            this.answer[3] = ((this.gameSmallStep() + 1) * Math.random()).toInt() + 1
        }
        if (this.gameLargeStep() > 2) {
            this.paintCmy[4] = this.variationCmy[list[4]]
            this.answer[4] = ((this.gameSmallStep() + 1) * Math.random()).toInt() + 1
        }
        if (this.gameLargeStep() > 3) {
            this.paintCmy[5] = this.variationCmy[list[5]]
            this.answer[5] = ((this.gameSmallStep() + 1) * Math.random()).toInt() + 1
        }
        this.slimmingAnswer()
        this.stageTargetColor(answer[0],answer[1],answer[2],answer[3],answer[4],answer[5])
    }

    // 2,2,4 --> 1,1,2 など最適化
    private fun slimmingAnswer() {
        this.slimmingAnswer2(7)
        this.slimmingAnswer2(6)
        this.slimmingAnswer2(5)
        this.slimmingAnswer2(4)
        this.slimmingAnswer2(3)
        this.slimmingAnswer2(2)
    }
    private fun slimmingAnswer2(num: Int) {
        var divisible: Boolean = true
        for (element in this.answer) {
            if (element % num != 0) {
                divisible = false
                break
            }
        }
        if (divisible) {
            for (i in this.answer.indices) {
                this.answer[i] /= num
            }
        }
    }

    private fun answerCheck() {
        this.vTextNext.alpha = 0F
        val textInts: Array<Int> = arrayOf(this.getTextInt(0),this.getTextInt(1),this.getTextInt(2),this.getTextInt(3),this.getTextInt(4),this.getTextInt(5))
        if (textInts[0] == 0 || textInts[0] % this.answer[0] != 0) {
            return
        }
        val sub: Int = textInts[0] / this.answer[0]
        if (this.answer[1] != 0) {
            if (textInts[1] % this.answer[1] != 0 || textInts[1] / this.answer[1] != sub) {
                return
            }
        }
        if (this.answer[2] != 0) {
            if (textInts[2] % this.answer[2] != 0 || textInts[2] / this.answer[2] != sub) {
                return
            }
        }
        if (this.answer[3] != 0) {
            if (textInts[3] % this.answer[3] != 0 || textInts[3] / this.answer[3] != sub) {
                return
            }
        }
        if (this.answer[4] != 0) {
            if (textInts[4] % this.answer[4] != 0 || textInts[4] / this.answer[4] != sub) {
                return
            }
        }
        if (this.answer[5] != 0) {
            if (textInts[5] % this.answer[5] != 0 || textInts[5] / this.answer[5] != sub) {
                return
            }
        }
        //Nice Job! Next...
        this.vTextNext.alpha = 1F
    }

    private fun stageTargetColor(n1: Int,n2: Int,n3: Int,n4: Int,n5: Int,n6: Int) {
        val cmy: Cmy = Cmy(0F,0F,0F)
        cmy.c += this.paintCmy[0].c * n1
        cmy.m += this.paintCmy[0].m * n1
        cmy.y += this.paintCmy[0].y * n1
        cmy.c += this.paintCmy[1].c * n2
        cmy.m += this.paintCmy[1].m * n2
        cmy.y += this.paintCmy[1].y * n2
        cmy.c += this.paintCmy[2].c * n3
        cmy.m += this.paintCmy[2].m * n3
        cmy.y += this.paintCmy[2].y * n3
        cmy.c += this.paintCmy[3].c * n4
        cmy.m += this.paintCmy[3].m * n4
        cmy.y += this.paintCmy[3].y * n4
        cmy.c += this.paintCmy[4].c * n5
        cmy.m += this.paintCmy[4].m * n5
        cmy.y += this.paintCmy[4].y * n5
        cmy.c += this.paintCmy[5].c * n6
        cmy.m += this.paintCmy[5].m * n6
        cmy.y += this.paintCmy[5].y * n6
        val max: Float = maxOf(cmy.c,cmy.m,cmy.y)
        if (max > 1) {
            cmy.c /= max
            cmy.m /= max
            cmy.y /= max
        }
        this.setTargetColor(this.cmyToRgb(cmy.c,cmy.m,cmy.y))
    }

    private fun stageMixColor() {
        val cmy: Cmy = Cmy(0F,0F,0F)
        for (i in 0..5) {
            if (this.vImagePaintColor[i].alpha == 1F) {
                val num: Int = this.getTextInt(i)
                cmy.c += this.paintCmy[i].c * num
                cmy.m += this.paintCmy[i].m * num
                cmy.y += this.paintCmy[i].y * num
            }
        }
        val max: Float = maxOf(cmy.c,cmy.m,cmy.y)
        if (max > 1) {
            cmy.c /= max
            cmy.m /= max
            cmy.y /= max
        }
        this.setMixColor(this.cmyToRgb(cmy.c,cmy.m,cmy.y))
    }

    private fun cmyToRgb(c: Float, m: Float, y: Float): Int {
        return Color.rgb(((1 - c) * 255).toInt(),((1 - m) * 255).toInt(),((1 - y) * 255).toInt())
    }

    private fun paintCmyToRgb(num: Int): Int {
        return Color.rgb(((1 - this.paintCmy[num].c) * 255).toInt(),((1 - this.paintCmy[num].m) * 255).toInt(),((1 - this.paintCmy[num].y) * 255).toInt())
    }

    private fun onClickReset() {
        if (this.vTextReset.alpha != 1F) {
            return
        }
        for (i in 0..5) {
            this.vTextPaintNum[i].text = "0"
        }
        this.vTextReset.alpha = 0F
        this.vTextNext.alpha = 0F
        this.stageMixColor()
        this.resetCount += 1
        if (this.resetCount > 2) {
            this.vTextGiveup.alpha = 1F
        }
    }

    private fun onClickGiveup() {
        if (this.vTextGiveup.alpha != 1F) {
            return
        }
        this.vTextGiveup.alpha = 0F
        val dialog = GiveupDialogFragment()
        dialog.show(supportFragmentManager,"")
    }
    override fun onGiveupDialogPositiveClick(dialog: DialogFragment) {
        for (i in 0..5) {
            this.vTextPaintNum[i].text = this.answer[i].toString()
            this.vTextPaintNum[i].setTextColor(Color.RED)
        }
        this.vTextReset.alpha = 0F
        this.vTextResume.alpha = 1F
    }
    override fun onGiveupDialogNegativeClick(dialog: DialogFragment) {
        this.vTextGiveup.alpha = 1F
    }

    private fun onClickResume() {
        if (this.vTextResume.alpha != 1F) {
            return
        }
        this.vTextResume.alpha = 0F
        this.game()
    }

    private fun onClickNext() {
        if (this.vTextNext.alpha != 1F) {
            return
        }
        this.vTextNext.alpha = 0F
        this.gameLevel += 1
        this.saveGameLevel()
        this.game()
    }

    private fun onClickPaintColor(num: Int) {
        if (this.vImagePaintColor[num].alpha != 1F) {
            return
        }
        if (this.vTextResume.alpha == 1F) {
            return
        }
        this.vTextReset.alpha = 1F
        this.addPaintText(num)
        this.stageMixColor()
        this.answerCheck()
    }

    private fun setTargetColor(c: Int) {
        this.vImageStageTarget.setColorFilter(c)
    }

    private fun setMixColor(c: Int) {
        this.vImageStageMix.setColorFilter(c)
    }

    private fun setPaintColor(num: Int) {
        this.vImagePaintColor[num].setColorFilter(this.paintCmyToRgb(num))
    }

    private fun setPaintAlpha(num: Int, alpha: Int) {
        val alpha2: Float = alpha.toFloat()
        this.vImagePaintColor[num].alpha = alpha2
        this.vImagePaintTray[num].alpha = alpha2
        this.vTextPaintNum[num].alpha = alpha2
    }

    private fun addPaintText(num: Int) {
        this.vTextPaintNum[num].text = (this.getTextInt(num) + 1).toString()
    }

    private fun getTextInt(num: Int): Int {
        return this.vTextPaintNum[num].text.toString().toInt()
    }

    //-------------------------------------------------

    private fun onClickSetting() {
        this.destroyFlag = true
        val intent = Intent(applicationContext, SettingActivity::class.java)
        intent.putExtra(THEME_NUMBER, this.themeNumber)
        intent.putExtra(LOCALE_LANGUAGE, this.localeLanguage)
        this.settingStartForResult.launch(intent)
    }

    //-------------------------------------------------

    //GameLevelを保存
    private fun saveGameLevel() {
        getSharedPreferences(SETTINGS, Context.MODE_PRIVATE).edit().apply {
            putInt(GAME_LEVEL, this@MainActivity.gameLevel)
            apply()
        }
    }

    //GameLevelを読み出し
    private fun loadGameLevel() {
        val pref = getSharedPreferences(SETTINGS, Context.MODE_PRIVATE)
        this.gameLevel = pref.getInt(GAME_LEVEL, 0)
    }

    //-------------------------------------------------

    //テーマを保存
    private fun saveThemeNumber() {
        getSharedPreferences(SETTINGS, Context.MODE_PRIVATE).edit().apply {
            putInt(THEME_NUMBER, this@MainActivity.themeNumber)
            apply()
        }
    }

    //テーマを読み出し
    private fun loadThemeNumber() {
        val pref = getSharedPreferences(SETTINGS, Context.MODE_PRIVATE)
        this.themeNumber = pref.getInt(THEME_NUMBER, 0)
    }

    //テーマを設定
    private fun setTheme() {
        when (this.themeNumber) {
            0 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
            1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
        }
    }

    //----------------------------------------------

    //localeLanguageを保存
    private fun saveLocaleLanguage() {
        getSharedPreferences(SETTINGS, Context.MODE_PRIVATE).edit().apply {
            putString(LOCALE_LANGUAGE, this@MainActivity.localeLanguage)
            apply()
        }
    }

    //localeLanguageを読み出し
    private fun loadLocaleLanguage() {
        val pref = getSharedPreferences(SETTINGS, Context.MODE_PRIVATE)
        this.localeLanguage = pref.getString(LOCALE_LANGUAGE, "") ?: ""
    }

    //言語設定
    override fun attachBaseContext(base: Context) {
        val pref = base.getSharedPreferences(SETTINGS, Context.MODE_PRIVATE)
        this.localeLanguage = pref.getString(LOCALE_LANGUAGE, "") ?: ""
        val loc: Locale? = if (this.localeLanguage != "") Locale(this.localeLanguage) else null
        if (loc != null) {
            val res = base.resources
            val config = Configuration(res.configuration)
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {    //minSdkVersion 24
                val localeList = LocaleList(loc)
                LocaleList.setDefault(localeList)
                config.setLocales(localeList)
            } else {    //minSdkVersion 17  16はダメ
                config.setLocale(loc)
            }
            super.attachBaseContext(base.createConfigurationContext(config))
        } else {
            super.attachBaseContext(base)
        }
    }

    //----------------------------------------------
}

app/src/main/java/jp/aosystem/mixingcolors/SettingActivity.kt

package jp.aosystem.mixingcolors

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.os.LocaleList
import android.widget.RadioButton
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
import java.util.*

class SettingActivity : AppCompatActivity() {

    private lateinit var vTextApply: TextView
    private lateinit var vTextCancel: TextView
    private lateinit var vSwitchResetLevel: SwitchCompat
    private lateinit var vSwitchTheme: SwitchCompat
    private lateinit var vRadioLanguageSystem: RadioButton
    private lateinit var vRadioLanguageEn: RadioButton
    private lateinit var vRadioLanguageBg: RadioButton
    private lateinit var vRadioLanguageCs: RadioButton
    private lateinit var vRadioLanguageDa: RadioButton
    private lateinit var vRadioLanguageDe: RadioButton
    private lateinit var vRadioLanguageEl: RadioButton
    private lateinit var vRadioLanguageEs: RadioButton
    private lateinit var vRadioLanguageEt: RadioButton
    private lateinit var vRadioLanguageFi: RadioButton
    private lateinit var vRadioLanguageFr: RadioButton
    private lateinit var vRadioLanguageHu: RadioButton
    private lateinit var vRadioLanguageIt: RadioButton
    private lateinit var vRadioLanguageJa: RadioButton
    private lateinit var vRadioLanguageLt: RadioButton
    private lateinit var vRadioLanguageLv: RadioButton
    private lateinit var vRadioLanguageNl: RadioButton
    private lateinit var vRadioLanguagePl: RadioButton
    private lateinit var vRadioLanguagePt: RadioButton
    private lateinit var vRadioLanguageRo: RadioButton
    private lateinit var vRadioLanguageRu: RadioButton
    private lateinit var vRadioLanguageSk: RadioButton
    private lateinit var vRadioLanguageSv: RadioButton
    private lateinit var vRadioLanguageTh: RadioButton
    private lateinit var vRadioLanguageZh: RadioButton

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_setting)
        //タイトルバー非表示
        supportActionBar?.hide()
        //
        this.vTextApply = findViewById(R.id.textApply)
        this.vTextCancel = findViewById(R.id.textCancel)
        this.vSwitchResetLevel = findViewById(R.id.switchResetLevel)
        this.vSwitchTheme = findViewById(R.id.switchTheme)
        this.vRadioLanguageSystem = findViewById(R.id.radioLanguageSystem)
        this.vRadioLanguageEn = findViewById(R.id.radioLanguageEn)
        //this.vRadioLanguageBg = findViewById(R.id.radioLanguageBg)
        //this.vRadioLanguageCs = findViewById(R.id.radioLanguageCs)
        //this.vRadioLanguageDa = findViewById(R.id.radioLanguageDa)
        //this.vRadioLanguageDe = findViewById(R.id.radioLanguageDe)
        //this.vRadioLanguageEl = findViewById(R.id.radioLanguageEl)
        //this.vRadioLanguageEs = findViewById(R.id.radioLanguageEs)
        //this.vRadioLanguageEt = findViewById(R.id.radioLanguageEt)
        //this.vRadioLanguageFi = findViewById(R.id.radioLanguageFi)
        //this.vRadioLanguageFr = findViewById(R.id.radioLanguageFr)
        //this.vRadioLanguageHu = findViewById(R.id.radioLanguageHu)
        //this.vRadioLanguageIt = findViewById(R.id.radioLanguageIt)
        this.vRadioLanguageJa = findViewById(R.id.radioLanguageJa)
        //this.vRadioLanguageLt = findViewById(R.id.radioLanguageLt)
        //this.vRadioLanguageLv = findViewById(R.id.radioLanguageLv)
        //this.vRadioLanguageNl = findViewById(R.id.radioLanguageNl)
        //this.vRadioLanguagePl = findViewById(R.id.radioLanguagePl)
        //this.vRadioLanguagePt = findViewById(R.id.radioLanguagePt)
        //this.vRadioLanguageRo = findViewById(R.id.radioLanguageRo)
        //this.vRadioLanguageRu = findViewById(R.id.radioLanguageRu)
        //this.vRadioLanguageSk = findViewById(R.id.radioLanguageSk)
        //this.vRadioLanguageSv = findViewById(R.id.radioLanguageSv)
        //this.vRadioLanguageTh = findViewById(R.id.radioLanguageTh)
        //this.vRadioLanguageZh = findViewById(R.id.radioLanguageZh)
        //データ受け取り
        val intent = this.intent
        val themeNumber: Int = intent.getIntExtra(MainActivity.THEME_NUMBER,0)
        this.vSwitchTheme.isChecked = themeNumber != 0
        val localeLanguage: String = intent.getStringExtra(MainActivity.LOCALE_LANGUAGE) ?: ""
        when (localeLanguage) {
            "en" -> this.vRadioLanguageEn.isChecked = true
            //"bg" -> this.vRadioLanguageBg.isChecked = true
            //"cs" -> this.vRadioLanguageCs.isChecked = true
            //"da" -> this.vRadioLanguageDa.isChecked = true
            //"de" -> this.vRadioLanguageDe.isChecked = true
            //"el" -> this.vRadioLanguageEl.isChecked = true
            //"es" -> this.vRadioLanguageEs.isChecked = true
            //"et" -> this.vRadioLanguageEt.isChecked = true
            //"fi" -> this.vRadioLanguageFi.isChecked = true
            //"fr" -> this.vRadioLanguageFr.isChecked = true
            //"hu" -> this.vRadioLanguageHu.isChecked = true
            //"it" -> this.vRadioLanguageIt.isChecked = true
            "ja" -> this.vRadioLanguageJa.isChecked = true
            //"lt" -> this.vRadioLanguageLt.isChecked = true
            //"lv" -> this.vRadioLanguageLv.isChecked = true
            //"nl" -> this.vRadioLanguageNl.isChecked = true
            //"pl" -> this.vRadioLanguagePl.isChecked = true
            //"pt" -> this.vRadioLanguagePt.isChecked = true
            //"ro" -> this.vRadioLanguageRo.isChecked = true
            //"ru" -> this.vRadioLanguageRu.isChecked = true
            //"sk" -> this.vRadioLanguageSk.isChecked = true
            //"sv" -> this.vRadioLanguageSv.isChecked = true
            //"th" -> this.vRadioLanguageTh.isChecked = true
            //"zh" -> this.vRadioLanguageZh.isChecked = true
            else -> this.vRadioLanguageSystem.isChecked = true
        }
        //onClickListener
        this.vTextApply.setOnClickListener {
            this.onClickApply()
        }
        this.vTextCancel.setOnClickListener {
            this.onClickCancel()
        }
    }

    private fun onClickApply() {
        val resetGameLevel: Int = if (this.vSwitchResetLevel.isChecked) 1 else 0
        val themeNumber: Int = if (this.vSwitchTheme.isChecked) 1 else 0
        var localeLanguage: String = ""
        if (this.vRadioLanguageEn.isChecked) {
            localeLanguage = "en"
            //} else if (this.vRadioLanguageBg.isChecked) {
            //    localeLanguage = "bg"
            //} else if (this.vRadioLanguageCs.isChecked) {
            //    localeLanguage = "cs"
            //} else if (this.vRadioLanguageDa.isChecked) {
            //    localeLanguage = "da"
            //} else if (this.vRadioLanguageDe.isChecked) {
            //    localeLanguage = "de"
            //} else if (this.vRadioLanguageEl.isChecked) {
            //    localeLanguage = "el"
            //} else if (this.vRadioLanguageEs.isChecked) {
            //    localeLanguage = "es"
            //} else if (this.vRadioLanguageEt.isChecked) {
            //    localeLanguage = "et"
            //} else if (this.vRadioLanguageFi.isChecked) {
            //    localeLanguage = "fi"
            //} else if (this.vRadioLanguageFr.isChecked) {
            //    localeLanguage = "fr"
            //} else if (this.vRadioLanguageHu.isChecked) {
            //    localeLanguage = "hu"
            //} else if (this.vRadioLanguageIt.isChecked) {
            //    localeLanguage = "it"
        } else if (this.vRadioLanguageJa.isChecked) {
            localeLanguage = "ja"
            //} else if (this.vRadioLanguageLt.isChecked) {
            //    localeLanguage = "lt"
            //} else if (this.vRadioLanguageLv.isChecked) {
            //    localeLanguage = "lv"
            //} else if (this.vRadioLanguageNl.isChecked) {
            //    localeLanguage = "nl"
            //} else if (this.vRadioLanguagePl.isChecked) {
            //    localeLanguage = "pl"
            //} else if (this.vRadioLanguagePt.isChecked) {
            //    localeLanguage = "pt"
            //} else if (this.vRadioLanguageRo.isChecked) {
            //    localeLanguage = "ro"
            //} else if (this.vRadioLanguageRu.isChecked) {
            //    localeLanguage = "ru"
            //} else if (this.vRadioLanguageSk.isChecked) {
            //    localeLanguage = "sk"
            //} else if (this.vRadioLanguageSv.isChecked) {
            //    localeLanguage = "sv"
            //} else if (this.vRadioLanguageTh.isChecked) {
            //    localeLanguage = "th"
            //} else if (this.vRadioLanguageZh.isChecked) {
            //    localeLanguage = "zh"
        }
        val intent = Intent()
        intent.putExtra(MainActivity.RESET_GAME_LEVEL, resetGameLevel)
        intent.putExtra(MainActivity.THEME_NUMBER, themeNumber)
        intent.putExtra(MainActivity.LOCALE_LANGUAGE, localeLanguage)
        setResult(Activity.RESULT_OK, intent)
        finish()
    }

    private fun onClickCancel() {
        val intent = Intent()
        setResult(Activity.RESULT_CANCELED, intent)
        finish()
    }

    //--------------------------------------------------

    //言語設定
    override fun attachBaseContext(base: Context) {
        val pref = base.getSharedPreferences(MainActivity.SETTINGS, Context.MODE_PRIVATE)
        val localeLanguage: String = pref.getString(MainActivity.LOCALE_LANGUAGE, "") ?: ""
        val loc: Locale? = if (localeLanguage != "") Locale(localeLanguage) else null
        if (loc != null) {
            val res = base.resources
            val config = Configuration(res.configuration)
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {    //minSdkVersion 24
                val localeList = LocaleList(loc)
                LocaleList.setDefault(localeList)
                config.setLocales(localeList)
            } else {    //minSdkVersion 17  16はダメ
                config.setLocale(loc)
            }
            super.attachBaseContext(base.createConfigurationContext(config))
        } else {
            super.attachBaseContext(base)
        }
    }

    //--------------------------------------------------
}

app/src/main/java/jp/aosystem/mixingcolors/GiveupDialogFragment.kt

package jp.aosystem.mixingcolors

import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import androidx.fragment.app.DialogFragment

class GiveupDialogFragment: DialogFragment() {

    public interface GiveupDialogLister {
        public fun onGiveupDialogPositiveClick(dialog:DialogFragment)
        public fun onGiveupDialogNegativeClick(dialog:DialogFragment)
    }

    private var mLister:GiveupDialogLister? = null

    override fun onAttach(context: Context) {
        super.onAttach(context)
        try {
            this.mLister = context as GiveupDialogLister
        } catch (e: ClassCastException) {
            throw ClassCastException("${context.toString()} must implement NoticeDialogListener")
        }
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val builder = AlertDialog.Builder(activity)
        val title: String = resources.getText(R.string.giveup).toString()
        builder.setTitle(title)
            //.setMessage(title)
            .setPositiveButton("ok") { dialog, id ->
                this.mLister?.onGiveupDialogPositiveClick(this)
            }
            .setNegativeButton("cancel") { dialog, id ->
                this.mLister?.onGiveupDialogNegativeClick(this)
            }
        return builder.create()
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override fun onDetach() {
        super.onDetach()
        this.mLister = null
    }
}

app/src/main/res/layout/activity_main.xml

<?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">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/layoutHeader"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="1dp"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/textLevel"
                    android:layout_width="wrap_content"
                    android:layout_height="48dp"
                    android:layout_marginStart="1dp"
                    android:layout_weight="3"
                    android:background="@color/main_level_bg"
                    android:gravity="center"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textSetting"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginStart="1dp"
                    android:layout_marginEnd="1dp"
                    android:layout_weight="1"
                    android:background="@color/main_setting_bg"
                    android:gravity="center"
                    android:text="@string/setting"
                    tools:ignore="TextContrastCheck" />

            </LinearLayout>

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/imageStageTarget"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:contentDescription="@string/dummy"
                    app:srcCompat="@drawable/ic_stage_target" />

                <ImageView
                    android:id="@+id/imageStageMix"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:contentDescription="@string/dummy"
                    app:srcCompat="@drawable/ic_stage_mix" />

                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:contentDescription="@string/dummy"
                    app:srcCompat="@drawable/ic_stage_brush" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom|end"
                    android:layout_marginEnd="30dp"
                    android:layout_marginBottom="30dp"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/textResume"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="end"
                        android:background="#fff"
                        android:paddingLeft="20dp"
                        android:paddingTop="5dp"
                        android:paddingRight="20dp"
                        android:paddingBottom="5dp"
                        android:text="@string/resume"
                        android:textColor="@color/black"
                        android:textSize="16sp" />

                    <TextView
                        android:id="@+id/textNext"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@android:color/holo_orange_light"
                        android:paddingStart="20dp"
                        android:paddingTop="5dp"
                        android:paddingEnd="20dp"
                        android:paddingBottom="5dp"
                        android:text="@string/niceJobNext"
                        android:textColor="@color/black"
                        android:textSize="20sp"
                        android:textStyle="bold" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginStart="30dp"
                    android:layout_marginBottom="30dp"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/textGiveup"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="15dp"
                        android:paddingTop="5dp"
                        android:paddingBottom="5dp"
                        android:text="@string/giveup"
                        android:textColor="@color/black"
                        android:textSize="14sp" />

                    <TextView
                        android:id="@+id/textReset"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingTop="10dp"
                        android:paddingBottom="10dp"
                        android:text="@string/reset"
                        android:textColor="@color/black"
                        android:textSize="14sp"
                        tools:ignore="TextContrastCheck" />
                </LinearLayout>

            </FrameLayout>

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp">

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1">

                        <TextView
                            android:id="@+id/textPaintNum1"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center"
                            android:text="@string/paintNum1"
                            android:textSize="24sp" />
                    </FrameLayout>

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1">

                        <TextView
                            android:id="@+id/textPaintNum2"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center"
                            android:text="@string/paintNum2"
                            android:textSize="24sp" />
                    </FrameLayout>

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1">

                        <TextView
                            android:id="@+id/textPaintNum3"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center"
                            android:text="@string/paintNum3"
                            android:textSize="24sp" />
                    </FrameLayout>
                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1">

                        <ImageView
                            android:id="@+id/imagePaintTray1"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_tray" />

                        <ImageView
                            android:id="@+id/imagePaintColor1"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_color" />

                    </FrameLayout>

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1">

                        <ImageView
                            android:id="@+id/imagePaintTray2"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_tray" />

                        <ImageView
                            android:id="@+id/imagePaintColor2"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_color" />

                    </FrameLayout>

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1">

                        <ImageView
                            android:id="@+id/imagePaintTray3"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_tray" />

                        <ImageView
                            android:id="@+id/imagePaintColor3"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_color" />

                    </FrameLayout>
                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1">

                        <TextView
                            android:id="@+id/textPaintNum4"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center"
                            android:text="@string/paintNum4"
                            android:textSize="24sp" />
                    </FrameLayout>

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1">

                        <TextView
                            android:id="@+id/textPaintNum5"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center"
                            android:text="@string/paintNum5"
                            android:textSize="24sp" />
                    </FrameLayout>

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1">

                        <TextView
                            android:id="@+id/textPaintNum6"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center"
                            android:text="@string/paintNum6"
                            android:textSize="24sp" />
                    </FrameLayout>
                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1">

                        <ImageView
                            android:id="@+id/imagePaintTray4"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_tray" />

                        <ImageView
                            android:id="@+id/imagePaintColor4"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_color" />
                    </FrameLayout>

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1">

                        <ImageView
                            android:id="@+id/imagePaintTray5"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_tray" />

                        <ImageView
                            android:id="@+id/imagePaintColor5"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_color" />

                    </FrameLayout>

                    <FrameLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1">

                        <ImageView
                            android:id="@+id/imagePaintTray6"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/dummy"
                            app:srcCompat="@drawable/ic_paint_tray" />

                        <ImageView
                            android:id="@+id/imagePaintColor6"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:adjustViewBounds="true"
                            android:contentDescription="@string/darkTheme"
                            app:srcCompat="@drawable/ic_paint_color" />

                    </FrameLayout>
                </TableRow>

            </TableLayout>

            <Space
                android:layout_width="match_parent"
                android:layout_height="200dp" />


        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/ad_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/activity_setting.xml

<?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=".SettingActivity">

    <LinearLayout
        android:id="@+id/layoutButtons"
        android:layout_width="match_parent"
        android:layout_height="48dip"
        android:layout_marginTop="1dp"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/textCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/setting_cancel_bg"
            android:gravity="center"
            android:minHeight="48dip"
            android:text="@string/cancel"
            tools:ignore="TextContrastCheck" />

        <TextView
            android:id="@+id/textApply"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="1dp"
            android:layout_weight="1"
            android:background="@color/setting_apply_bg"
            android:gravity="center"
            android:minHeight="48dip"
            android:text="@string/apply"
            tools:ignore="TextContrastCheck" />

    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/layoutButtons">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:orientation="vertical"
            android:paddingLeft="20dp"
            android:paddingTop="20dp"
            android:paddingRight="20dp"
            android:paddingBottom="50dp">

            <androidx.appcompat.widget.SwitchCompat
                android:id="@+id/switchResetLevel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:text="@string/resetLevel" />

            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/resetLevel1" />

            <View
                android:id="@+id/divider3"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="20dp"
                android:background="?android:attr/listDivider" />

            <androidx.appcompat.widget.SwitchCompat
                android:id="@+id/switchTheme"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:text="@string/darkTheme" />

            <View
                android:id="@+id/divider4"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="20dp"
                android:background="?android:attr/listDivider" />

            <TextView
                android:id="@+id/textLanguage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="@string/language"
                android:textColor="?android:attr/textColorPrimary" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="@string/languageNote" />

            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
                <RadioButton
                    android:id="@+id/radioLanguageSystem"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/languageSystem" />
                <RadioButton
                    android:id="@+id/radioLanguageEn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/languageEn" />

                <RadioButton
                    android:id="@+id/radioLanguageJa"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/languageJa" />

            </RadioGroup>

            <View
                android:id="@+id/divider"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="20dp"
                android:background="?android:attr/listDivider" />

            <TextView
                android:id="@+id/textUsage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="@string/usage" />

            <TextView
                android:id="@+id/textUsage1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="@string/usage1" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="120dp" />

        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
このページでお気付きの点がございましたら
ご連絡いただけますと幸いです。
Eメール(任意)
送信内容
 

便利ウェブサイト