ソースコード source code

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

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

下記コードの最終ビルド日: 2021-05-08

build.gradle

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

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

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

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

app/build.gradle

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

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "jp.aosystem.readaloud"
        minSdkVersion 26
        targetSdkVersion 30
        multiDexEnabled true
        versionCode 8
        versionName "1.7"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

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

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.android.gms:play-services-ads:20.1.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.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.readaloud">

    <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.ReadAloud">
        <activity android:name=".MainActivity">
            <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">
        </meta-data>
    </application>

</manifest>

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

package jp.aosystem.readaloud

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color
import android.os.Bundle
import android.os.LocaleList
import android.speech.tts.TextToSpeech
import android.speech.tts.UtteranceProgressListener
import android.util.DisplayMetrics
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.SeekBar
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.constraintlayout.widget.ConstraintLayout
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 jp.aosystem.readaloud.databinding.ActivityMainBinding
import java.util.*

class MainActivity : AppCompatActivity(), TextToSpeech.OnInitListener {
    private lateinit var binding: ActivityMainBinding
    private lateinit var viewModel: ConstraintLayout
    private var inputMethodManager: InputMethodManager? = null
    private var themeNumber: Int = 0    //0 or 1
    private var localeLanguage: String = ""
    private var tabNumber: Int = 1           //タブの番号
    private var tts: TextToSpeech? = null
    private var speed: Float = 1f
    private var pitch: Float = 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.binding.adContainer.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
        private const val RESULT_SETTING_ACTIVITY: Int = 1
        internal const val SETTINGS: String = "settings"
        internal const val THEME_NUMBER: String = "themeNumber"
        internal const val LOCALE_LANGUAGE: String = "localeLanguage"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_main)
        this.binding = ActivityMainBinding.inflate(layoutInflater)
        this.viewModel = this.binding.root
        setContentView(this.viewModel)
        //タイトルバー非表示
        supportActionBar?.hide()
        //テーマ読み込みと設定
        this.loadThemeNumber()
        this.setTheme()
        //adMob
        MobileAds.initialize(this) {}
        adView = AdView(this)
        this.binding.adContainer.addView(adView)
        loadBanner()
        //
        this.tts = TextToSpeech(this, this)
        //シークバー
        this.seekBarInit()
        //背景タッチでテキストエリアからフォーカスを外してキーボードを隠す
        this.setTouchListener()
        //
        this.tabColorClear()
        this.binding.textTab1.setTextColor(Color.WHITE)
    }

    override fun onResume() {
        super.onResume()
        this.tabNumber = 1
        this.loadText()
    }

    private fun loadBanner() {
        adView.adUnitId = AD_UNIT_ID
        adView.adSize = adSize
        // Create an ad request. Check your logcat output for the hashed device ID to
        // get test ads on a physical device, e.g.,
        // "Use AdRequest.Builder.addTestDevice("ABCDE0123") to get test ads on this device."
        val adRequest = AdRequest
            .Builder()
            //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build()
        // Start loading the ad in the background.
        adView.loadAd(adRequest)
    }


    override fun onStop() {
        super.onStop()
        this.saveText(this.binding.editText1.text.toString())
    }

    //背景タッチでテキストエリアからフォーカスを外してキーボードを隠す
    private fun setTouchListener() {
        this.inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
        this.binding.editText1.setOnFocusChangeListener { _, hasFocus ->
            if (!hasFocus) {
                this.inputMethodManager!!.hideSoftInputFromWindow(   //キーボードを隠す
                    this.binding.editText1.windowToken,
                    InputMethodManager.HIDE_NOT_ALWAYS
                )
            }
        }
    }

    private fun tabColorClear() {
        this.binding.textTab1.setTextColor(Color.BLACK)
        this.binding.textTab2.setTextColor(Color.BLACK)
        this.binding.textTab3.setTextColor(Color.BLACK)
        this.binding.textTab4.setTextColor(Color.BLACK)
        this.binding.textTab5.setTextColor(Color.BLACK)
        this.binding.textTab6.setTextColor(Color.BLACK)
        this.binding.textTab7.setTextColor(Color.BLACK)
        this.binding.textTab8.setTextColor(Color.BLACK)
        this.binding.textTab9.setTextColor(Color.BLACK)
    }
    fun onClickTab1(v: View) {
        this.saveText(this.binding.editText1.text.toString())
        this.tabNumber = 1
        this.loadText()
        this.tabColorClear()
        this.binding.textTab1.setTextColor(Color.WHITE)
    }
    fun onClickTab2(v: View) {
        this.saveText(this.binding.editText1.text.toString())
        this.tabNumber = 2
        this.loadText()
        this.tabColorClear()
        this.binding.textTab2.setTextColor(Color.WHITE)
    }
    fun onClickTab3(v: View) {
        this.saveText(this.binding.editText1.text.toString())
        this.tabNumber = 3
        this.loadText()
        this.tabColorClear()
        this.binding.textTab3.setTextColor(Color.WHITE)
    }
    fun onClickTab4(v: View) {
        this.saveText(this.binding.editText1.text.toString())
        this.tabNumber = 4
        this.loadText()
        this.tabColorClear()
        this.binding.textTab4.setTextColor(Color.WHITE)
    }
    fun onClickTab5(v: View) {
        this.saveText(this.binding.editText1.text.toString())
        this.tabNumber = 5
        this.loadText()
        this.tabColorClear()
        this.binding.textTab5.setTextColor(Color.WHITE)
    }
    fun onClickTab6(v: View) {
        this.saveText(this.binding.editText1.text.toString())
        this.tabNumber = 6
        this.loadText()
        this.tabColorClear()
        this.binding.textTab6.setTextColor(Color.WHITE)
    }
    fun onClickTab7(v: View) {
        this.saveText(this.binding.editText1.text.toString())
        this.tabNumber = 7
        this.loadText()
        this.tabColorClear()
        this.binding.textTab7.setTextColor(Color.WHITE)
    }
    fun onClickTab8(v: View) {
        this.saveText(this.binding.editText1.text.toString())
        this.tabNumber = 8
        this.loadText()
        this.tabColorClear()
        this.binding.textTab8.setTextColor(Color.WHITE)
    }
    fun onClickTab9(v: View) {
        this.saveText(this.binding.editText1.text.toString())
        this.tabNumber = 9
        this.loadText()
        this.tabColorClear()
        this.binding.textTab9.setTextColor(Color.WHITE)
    }

    //テキストを保存
    private fun saveText(str: String) {
        getSharedPreferences("settings", Context.MODE_PRIVATE).edit().apply {
            when (this@MainActivity.tabNumber) {
                1 -> putString("editText1", str)
                2 -> putString("editText2", str)
                3 -> putString("editText3", str)
                4 -> putString("editText4", str)
                5 -> putString("editText5", str)
                6 -> putString("editText6", str)
                7 -> putString("editText7", str)
                8 -> putString("editText8", str)
                9 -> putString("editText9", str)
            }
            apply()
        }
    }

    //テキストを読み出し
    private fun loadText() {
        val pref = getSharedPreferences("settings", Context.MODE_PRIVATE)
        var editText: String = ""
        when (this.tabNumber) {
            1 -> editText = pref.getString("editText1", "").toString()
            2 -> editText = pref.getString("editText2", "").toString()
            3 -> editText = pref.getString("editText3", "").toString()
            4 -> editText = pref.getString("editText4", "").toString()
            5 -> editText = pref.getString("editText5", "").toString()
            6 -> editText = pref.getString("editText6", "").toString()
            7 -> editText = pref.getString("editText7", "").toString()
            8 -> editText = pref.getString("editText8", "").toString()
            9 -> editText = pref.getString("editText9", "").toString()
        }
        this.binding.editText1.setText(editText, TextView.BufferType.NORMAL)
    }

    override fun onInit(status: Int) {
        if (status == TextToSpeech.SUCCESS) {
            //Toast.makeText(applicationContext, "初期化成功", Toast.LENGTH_SHORT).show()
            if (this.tts?.isLanguageAvailable(Locale.JAPANESE)!! > TextToSpeech.LANG_AVAILABLE) {
                this.binding.textPlayJp.isEnabled = false
            }
            if (this.tts?.isLanguageAvailable(Locale.ENGLISH)!! > TextToSpeech.LANG_AVAILABLE) {
                this.binding.textPlayEn.isEnabled = false
            }
            val listener = object : UtteranceProgressListener(){
                override fun onDone(utteranceId: String?) {
                    val text: String = resources.getString(R.string.ttsDone)
                    Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
                }
                override fun onError(utteranceId: String?) {
                    val text: String = resources.getString(R.string.ttsError)
                    Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
                }
                override fun onError(utteranceId: String?, errorCode: Int) {
                    val text: String = resources.getString(R.string.ttsError)
                    Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
                }
                override fun onStart(utteranceId: String?) {
                    val text: String = resources.getString(R.string.ttsStart)
                    Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
                }
                override fun onStop(utteranceId: String?, interrupted: Boolean) {
                    val text: String = resources.getString(R.string.ttsStop)
                    Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
                }
                override fun onBeginSynthesis(utteranceId: String?,sampleRateInHz: Int,audioFormat: Int, channelCount: Int) {
                    val text: String = resources.getString(R.string.ttsBeginSynthesis)
                    Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
                }
                override fun onAudioAvailable(utteranceId: String?, audio: ByteArray?) {
                    val text: String = resources.getString(R.string.ttsAudioAvailable)
                    Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
                }
            }
            this.tts?.setOnUtteranceProgressListener(listener)  //イベントリスナを登録
        } else {
            val text: String = resources.getString(R.string.ttsInitError)
            Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
        }
    }

    override fun onDestroy() {
        this.saveText(this.binding.editText1.text.toString())
        this.tts?.shutdown()
        super.onDestroy()
    }

    private fun seekBarInit() {
        this.binding.seekBarSpeed.progress = 10
        this.binding.seekBarSpeed.min = 2
        this.binding.seekBarSpeed.max = 30
        this.binding.seekBarPitch.progress = 10
        this.binding.seekBarPitch.min = 2
        this.binding.seekBarPitch.max = 30

        this.binding.seekBarSpeed.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(
                seekBar: SeekBar,
                progress: Int,
                fromUser: Boolean
            ) {   //ツマミがドラッグされると呼ばれる
                this@MainActivity.speed = progress.toFloat() / 10f
                val str = String.format(Locale.US, "%d%%", (this@MainActivity.speed * 100).toInt())
                this@MainActivity.binding.textSpeed.text = str
                this@MainActivity.tts?.setSpeechRate(this@MainActivity.speed)
            }

            override fun onStartTrackingTouch(seekBar: SeekBar) {   //ツマミがタッチされた時に呼ばれる
            }

            override fun onStopTrackingTouch(seekBar: SeekBar) {    //ツマミがリリースされた時に呼ばれる
            }
        })
        this.binding.seekBarPitch.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(
                seekBar: SeekBar,
                progress: Int,
                fromUser: Boolean
            ) {   //ツマミがドラッグされると呼ばれる
                this@MainActivity.pitch = progress.toFloat() / 10f
                val str = String.format(Locale.US, "%d%%", (this@MainActivity.pitch * 100).toInt())
                this@MainActivity.binding.textPitch.text = str
                this@MainActivity.tts?.setPitch(this@MainActivity.pitch)
            }

            override fun onStartTrackingTouch(seekBar: SeekBar) {   //ツマミがタッチされた時に呼ばれる
            }

            override fun onStopTrackingTouch(seekBar: SeekBar) {    //ツマミがリリースされた時に呼ばれる
            }
        })
    }

    fun onClickPlayJp(v: View) {
        this.tts?.language = Locale.JAPANESE
        this.speechText()
    }

    fun onClickPlayEn(v: View) {
        this.tts?.language = Locale.ENGLISH
        this.speechText()
    }

    fun onClickStop(v: View) {
        this.tts?.shutdown()
        this.tts = TextToSpeech(this, this)
    }

    private fun speechText() {
        this.tts?.setSpeechRate(this.speed)
        this.tts?.setPitch(this.pitch)
        val text = this.binding.editText1.text.toString()
        this.tts?.speak(text, TextToSpeech.QUEUE_FLUSH, null, "ID")
    }

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

    fun onClickSetting(v: View) {
        val intent = Intent(applicationContext, SettingActivity::class.java)
        intent.putExtra(THEME_NUMBER, this.themeNumber)
        intent.putExtra(LOCALE_LANGUAGE, this.localeLanguage)
        startActivityForResult(intent, RESULT_SETTING_ACTIVITY)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
        super.onActivityResult(requestCode, resultCode, intent)
        if (resultCode == Activity.RESULT_OK && requestCode == RESULT_SETTING_ACTIVITY && intent != null) {
            var reCreateFlag: Boolean = false
            //
            val lastThemeNumber: Int = this.themeNumber
            this.themeNumber = intent.getIntExtra(THEME_NUMBER, 0)
            if (this.themeNumber != lastThemeNumber) {
                this.saveThemeNumber()
                reCreateFlag = true
            }
            //
            val lastLocaleLanguage = this.localeLanguage
            this.localeLanguage = intent.getStringExtra(LOCALE_LANGUAGE) ?: ""
            if (this.localeLanguage != lastLocaleLanguage) {
                this.saveLocaleLanguage()
                reCreateFlag = true
            }
            //
            if (reCreateFlag) {
                recreate()
            }
        }
    }

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

    //テーマを保存
    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()
        }
    }

    //言語設定
    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)
            val localeList = LocaleList(loc)
            LocaleList.setDefault(localeList)
            config.setLocales(localeList)
            super.attachBaseContext(base.createConfigurationContext(config))
        } else {
            super.attachBaseContext(base)
        }
    }

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

}

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

package jp.aosystem.readaloud

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import android.os.LocaleList
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import jp.aosystem.readaloud.databinding.ActivitySettingBinding
import java.util.*

class SettingActivity : AppCompatActivity() {
    private lateinit var binding: ActivitySettingBinding
    private lateinit var viewModel: ConstraintLayout

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_main)
        this.binding = ActivitySettingBinding.inflate(layoutInflater)
        this.viewModel = this.binding.root
        setContentView(this.viewModel)
        //データ受け取り
        val intent = this.intent
        val themeNumber: Int = intent.getIntExtra(MainActivity.THEME_NUMBER,0)
        this.binding.switchTheme.isChecked = themeNumber != 0
        val localeLanguage: String = intent.getStringExtra(MainActivity.LOCALE_LANGUAGE) ?: ""
        when (localeLanguage) {
            "en" -> this.binding.radioLanguageEn.isChecked = true
            "ja" -> this.binding.radioLanguageJa.isChecked = true
            else -> this.binding.radioLanguageSystem.isChecked = true
        }
        //タイトルバー非表示
        supportActionBar?.hide()
    }

    fun onClickApply(v: View) {
        val themeNumber = if (this.binding.switchTheme.isChecked) 1 else 0
        var localeLanguage: String = ""
        if (this.binding.radioLanguageEn.isChecked) {
            localeLanguage = "en"
        } else if (this.binding.radioLanguageJa.isChecked) {
            localeLanguage = "ja"
        }
        val intent = Intent()
        intent.putExtra(MainActivity.THEME_NUMBER, themeNumber)
        intent.putExtra(MainActivity.LOCALE_LANGUAGE, localeLanguage)
        setResult(Activity.RESULT_OK, intent)
        finish()
    }

    fun onClickCancel(v: View) {
        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)
            val localeList = LocaleList(loc)
            LocaleList.setDefault(localeList)
            config.setLocales(localeList)
            super.attachBaseContext(base.createConfigurationContext(config))
        } else {
            super.attachBaseContext(base)
        }
    }

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

}

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

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        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="horizontal">

            <TextView
                android:id="@+id/textTitle"
                android:layout_width="wrap_content"
                android:layout_height="48dp"
                android:layout_weight="5"
                android:background="#FFB74D"
                android:gravity="center"
                android:text="@string/title" />

            <TextView
                android:id="@+id/textSetting"
                android:layout_width="wrap_content"
                android:layout_height="48dp"
                android:layout_weight="1"
                android:background="#FFD54F"
                android:gravity="center"
                android:onClick="onClickSetting"
                android:text="@string/setting" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/textTab1"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_weight="1"
                android:background="#EF9A9A"
                android:gravity="center"
                android:onClick="onClickTab1"
                android:text="@string/tab1" />

            <TextView
                android:id="@+id/textTab2"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_weight="1"
                android:background="#F48FB1"
                android:gravity="center"
                android:onClick="onClickTab2"
                android:text="@string/tab2" />

            <TextView
                android:id="@+id/textTab3"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_weight="1"
                android:background="#CE93D8"
                android:gravity="center"
                android:onClick="onClickTab3"
                android:text="@string/tab3" />

            <TextView
                android:id="@+id/textTab4"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_weight="1"
                android:background="#B39DDB"
                android:gravity="center"
                android:onClick="onClickTab4"
                android:text="@string/tab4" />

            <TextView
                android:id="@+id/textTab5"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_weight="1"
                android:background="#9FA8DA"
                android:gravity="center"
                android:onClick="onClickTab5"
                android:text="@string/tab5" />

            <TextView
                android:id="@+id/textTab6"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_weight="1"
                android:background="#90CAF9"
                android:gravity="center"
                android:onClick="onClickTab6"
                android:text="@string/tab6" />

            <TextView
                android:id="@+id/textTab7"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_weight="1"
                android:background="#81D4FA"
                android:gravity="center"
                android:onClick="onClickTab7"
                android:text="@string/tab7" />

            <TextView
                android:id="@+id/textTab8"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_weight="1"
                android:background="#80CBC4"
                android:gravity="center"
                android:onClick="onClickTab8"
                android:text="@string/tab8" />

            <TextView
                android:id="@+id/textTab9"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_weight="1"
                android:background="#A5D6A7"
                android:gravity="center"
                android:onClick="onClickTab9"
                android:text="@string/tab9" />
        </LinearLayout>

        <ScrollView
            android:id="@+id/scrollView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:id="@+id/inner_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:orientation="vertical">


                <EditText
                    android:id="@+id/editText1"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginRight="5dp"
                    android:autofillHints=""
                    android:background="@drawable/edit_text_border"
                    android:ems="10"
                    android:gravity="start|top"
                    android:inputType="textMultiLine"
                    android:padding="8dp" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="30dp"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/textView5"
                        android:layout_width="20dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="15dp"
                        android:layout_weight="2"
                        android:text="Speed" />

                    <TextView
                        android:id="@+id/text_speed"
                        android:layout_width="10dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="10dp"
                        android:layout_weight="2"
                        android:text="100%" />

                    <SeekBar
                        android:id="@+id/seekBarSpeed"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="10" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="30dp"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/textView6"
                        android:layout_width="20dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="15dp"
                        android:layout_weight="2"
                        android:text="Pitch" />

                    <TextView
                        android:id="@+id/text_pitch"
                        android:layout_width="10dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="10dp"
                        android:layout_weight="2"
                        android:text="100%" />

                    <SeekBar
                        android:id="@+id/seekBarPitch"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="10" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="30dp"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/textPlayJp"
                        android:layout_width="wrap_content"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:background="#4FC3F7"
                        android:gravity="center"
                        android:onClick="onClickPlayJp"
                        android:text="@string/japanese" />

                    <TextView
                        android:id="@+id/textPlayEn"
                        android:layout_width="wrap_content"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:background="#81C784"
                        android:gravity="center"
                        android:onClick="onClickPlayEn"
                        android:text="@string/english" />

                    <TextView
                        android:id="@+id/textStop"
                        android:layout_width="wrap_content"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:background="#FFB74D"
                        android:gravity="center"
                        android:onClick="onClickStop"
                        android:text="@string/stop" />

                </LinearLayout>


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

            </LinearLayout>


        </ScrollView>

    </LinearLayout>

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

    </LinearLayout>

</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: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="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="6"
            android:background="#FDD835"
            android:gravity="center"
            android:minHeight="48dip"
            android:onClick="onClickCancel"
            android:text="@android:string/cancel" />

        <TextView
            android:id="@+id/textVerification"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="6"
            android:background="#C0CA33"
            android:gravity="center"
            android:minHeight="48dip"
            android:onClick="onClickApply"
            android:text="@string/apply" />

    </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/switchTheme"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/darkTheme" />


            <View
                android:id="@+id/divider5"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="10dp"
                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" />

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

            <Space
                android:layout_width="match_parent"
                android:layout_height="150dp" />
        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>